String getnetip (string ipaddr) {URL infourl = NULL; inputstream instream = NULL; try {infourl = new URL (ipaddr); urlconnection connection = infourl. openconnection (); httpurlconnection httpconnection = (httpurlconnection) connection; int responsecode = httpconnection. getresponsecode (); If (responsecode = httpurlconnection. http_ OK) {instream = httpconnection. getinputstream (); bufferedreader reader = New bufferedreader (New inputstreamreader (instream, "UTF-8"); stringbuilder strber = new stringbuilder (); string line = NULL; while (line = reader. Readline ())! = NULL) strber. append (LINE + "\ n"); instream. close (); Return strber. tostring () ;}} catch (malformedurlexception e) {// todo auto-generated Catch Block E. printstacktrace ();} catch (ioexception e) {// todo auto-generated Catch Block E. printstacktrace ();} return "";}
View System. out. println (getnetip ("http://fw.qq.com/ipaddress");
Add permission
obtain the outer IP address from the http://f?qq.com/ipaddress