Android 查看本机外网IP
2011-07-07 20:10
357 查看
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 ""; }
查看 System.out.println((GetNetIp("http://fw.qq.com/ipaddress")));
加权限 <uses-permission android:name="android.permission.INTERNET"></uses-permission>
通过获取http://fw.qq.com/ipaddress网页取得外网IP
相关文章推荐
- Android 查看本机外网IP .
- Android 查看本机外网IP
- android通过执行netstat及cat /proc/net/tcp查看正在运行应用的本地端口号pid和uid以及对方的IP和端口号
- Android Things启动在树莓派后,直接运行程序,无法查看主界面的IP
- 查看ADSL无线路由外网IP的方法
- 使用命令查看自己的外网IP地址
- linux内网机器如何查看本地外网ip
- IP常识(一):如何设置、查看本机内网IP、外网IP
- ubuntu下如何查看自己的外网IP
- 如何获取Android手机连接当前网络的外网IP
- Android获取外网IP地址
- 使用命令查看自己的外网IP地址
- 下如何查看外网的IP
- linux内网机器如何查看本地外网ip
- linux 查看外网IP
- android如何查看网卡名和ip
- Android获取外网ip
- linux下查看外网出口IP
- linux查看本机外网ip
- linux shell查看当前外网IP