public class Test {public static void main (string[] args) {try {String ip1 = Getmyip ();
System.out.println ("MyIP:" + ip1);
String ip2 = getmyiplocal ();
System.out.println ("Mylocalip:" + ip2);
catch (IOException E1) {e1.printstacktrace ();
} private static String Getmyip () throws IOException {InputStream ins = null;
try {URL url = new URL ("http://iframe.ip138.com/ic.asp");
URLConnection con = url.openconnection ();
INS = Con.getinputstream ();
InputStreamReader Isreader = new InputStreamReader (INS, "GB2312");
BufferedReader breader = new BufferedReader (Isreader);
StringBuffer webcontent = new StringBuffer ();
String str = NULL;
while (str = Breader.readline ())!= null) {webcontent.append (str);
int start = Webcontent.indexof ("[") + 1;
int end = Webcontent.indexof ("]");
Return webcontent.substring (start, end);
finally {if (INS!= null) {ins.close (); }} private static String getmyiplocal() throws IOException {inetaddress ia = inetaddress.getlocalhost ();
return ia.gethostaddress ();
}
}