Android(安卓)查看本机外网IP
16lz
2022-04-01
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(安卓)TextView显示html图片
- Android(安卓)获取activity栈中activity
- Android获取设备信息(利用反射)
- android基于AndPermission的权限申请封装类
- Android(安卓)中文API:如何安全的为APK进行签名?
- android 显示 网络图片
- Android(安卓)文件打开方式
- 第一代Android壳源码--某某公司早期壳代码加固原理分析
- Android中获取屏幕长宽的方法