Package com.ning;
Import Java.io.BufferedReader;
Import Java.io.InputStreamReader;
Import Java.net.URL;
public class Listip {
public static void Main (string[] args) throws Exception {
SYSTEM.OUT.PRINTLN ("This machine's extranet IP is:"
+ LISTIP.GETWEBIP ("http://iframe.ip138.com/ic.asp"));
+ LISTIP.GETWEBIP ("http://www.ip138.com"));
+ LISTIP.GETWEBIP ("http://1111.ip138.com/ic.asp"));
}
public static string Getwebip (string strurl) {
try {
URL url = new URL (strurl);
BufferedReader br = new BufferedReader (New InputStreamReader (Url.openstream (), "GB2312"));
String s = "";
StringBuffer sb = new StringBuffer ("");
String webcontent = "";
while ((s = br.readline ()) = null) {
Sb.append (S + "RN");
}
Br.close ();
WebContent = Sb.tostring ();
int start = Webcontent.indexof ("[") + 1;
int end = Webcontent.indexof ("]");
System.out.println ("webcontent=" + webcontent);
System.out.println ("start=" + start);
System.out.println ("end=" + end);
if (Start < 0 | | End < 0) {
return null;
}
WebContent = webcontent.substring (start, end);
return webcontent;
} catch (Exception e) {
E.printstacktrace ();
Return "Error open URL:" + strurl;
}
}
}
Get the native extranet IP address