Tag:wifi Extranet IP access get extranet ip
<span style= "FONT-SIZE:18PX;" >//get extranet ippublic static String Getnetip () {URL Infourl = Null;inputstream instream = null;try {//HTTP://IFRAME.IP138.C om/ic.asp//infourl = new URL ("http://city.ip138.com/city0.asp"); infourl = new URL ("http://ip38.com"); 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 ();//extract IP ground from the results of the feedback Address//int start = Strber.indexof ("[");//LOG.D ("Zph", "" "+ start);//int end = Strber.indexof ("] ", start + 1);//LOG.D (" Zph " , "+ End", line = strber.substring (378, 395), Line.replaceall ("", ""); return line;}} catch (MalformedurlexceptiOn e) {e.printstacktrace ();} catch (IOException e) {e.printstacktrace ();} return null;} </span>
Another high-end approach to acquiring an extranet IP
public static string Getnetip () {String IP = ""; try{string address = "Http://ip.taobao.com/service/getIpInfo2.php?ip=myip"; URL url = new URL (address); HttpURLConnection connection = (httpurlconnection) url.openconnection (); connection.setusecaches (false); if ( Connection.getresponsecode () = = HTTPURLCONNECTION.HTTP_OK) {InputStream in = Connection.getinputstream ();// Converts the stream into a string BufferedReader reader = new BufferedReader (new InputStreamReader (in)); String tmpstring = ""; StringBuilder Retjson = new StringBuilder (); while ((tmpstring = Reader.readline ()) = null) {retjson.append (tmpstring + "\ n ");} Jsonobject jsonobject = new Jsonobject (retjson.tostring ()); String code = jsonobject.getstring ("code"), if (Code.equals ("0")) {Jsonobject data = Jsonobject.getjsonobject ("Data"); P = data.getstring ("IP") + "(" + data.getstring ("country") + data.getstring ("area") + "zone" + data.getstring ("region") + data. GetString ("city") + data.getstring ("ISP") + ")"; LOG.E ("Prompt", "Your IP address is:" + IP);} Else{ip = ""; LOG.E ("Hint", "IP interface exception, unable to obtainTake the IP address! ");}} Else{ip = ""; LOG.E ("Hint", "network connection is abnormal, unable to get IP address!") ");}} catch (Exception e) {IP = ""; LOG.E ("Hint", "an exception occurred when getting IP address, exception information is:" + e.tostring ());} return IP;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
How to get WiFi extranet IP from Android