/***** @ Param ipaddr * @ return public IP */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 = httpconnecti On. 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); 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 "";}
The input address can be
http://automation.whatismyip.com/n09230945.asp