Java: Obtenir l’adresse IP publique d’un PC

Author:

 int,string,char,static, url, socket, url, socket, java
{filelink=23}

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package publicationpro;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;

/**
 *
 * @author Administrateur Sako Adams
 */
public class NativeIP {

        public static String getIP() throws Exception {
        URL whatismyip = new URL("http://checkip.amazonaws.com");
        BufferedReader in = null;
        try {
            in = new BufferedReader(new InputStreamReader(
                    whatismyip.openStream()));
            String ip = in.readLine();
            return ip;
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
        public static void main(String...args) throws Exception
        {
          System.out.println(getIP());
        }
}

A Voir sur le même Sujet:

  • obtenir donnée ordinateur java
  • java : exemple String[]
  • Adresse ip publique
  • chercher l’adresse ip d’une machine donnée, www.ump.ma par exemple. inetaddress
  • adresse IP dynamique
  • programmation réseaux java