获取安卓设备上有线网或者无线网络的IP地址
来源:互联网 发布:java mvc框架 编辑:程序博客网 时间:2024/05/04 13:35
/** * 获取安卓设备当前的IP地址(有线或无线) * * @return */ private String getClientIP() { try { // 获取本地设备的所有网络接口 Enumeration<NetworkInterface> enumerationNi = NetworkInterface .getNetworkInterfaces(); while (enumerationNi.hasMoreElements()) { NetworkInterface networkInterface = enumerationNi.nextElement(); String interfaceName = networkInterface.getDisplayName(); Log.i("tag", "网络名字" + interfaceName); // 如果是有限网卡 if (interfaceName.equals("eth0")) { Enumeration<InetAddress> enumIpAddr = networkInterface .getInetAddresses(); while (enumIpAddr.hasMoreElements()) { // 返回枚举集合中的下一个IP地址信息 InetAddress inetAddress = enumIpAddr.nextElement(); // 不是回环地址,并且是ipv4的地址 if (!inetAddress.isLoopbackAddress() && inetAddress instanceof Inet4Address) { Log.i("tag", inetAddress.getHostAddress() + " "); return inetAddress.getHostAddress(); } } // 如果是无限网卡 } else if (interfaceName.equals("wlan0")) { Enumeration<InetAddress> enumIpAddr = networkInterface .getInetAddresses(); while (enumIpAddr.hasMoreElements()) { // 返回枚举集合中的下一个IP地址信息 InetAddress inetAddress = enumIpAddr.nextElement(); // 不是回环地址,并且是ipv4的地址 if (!inetAddress.isLoopbackAddress() && inetAddress instanceof Inet4Address) { Log.i("tag", inetAddress.getHostAddress() + " "); return inetAddress.getHostAddress(); } } } } } catch (SocketException e) { e.printStackTrace(); } return ""; }
阅读全文
0 0
- 获取安卓设备上有线网或者无线网络的IP地址
- Android获取有线网ip地址
- java获取有线网络的ip地址 与mac地址
- 安卓获取接入的Wifi热点设备的Ip地址
- android开发 获取WIFI和有线的IP地址
- Android中获取有线网络的IP地址
- android开发 获取WIFI和有线的IP地址
- android获取有线网的Mac地址
- wince获取IP地址,无线和有线
- 连接设备上的有线
- 获取设备IP地址
- 安卓获取本机ip地址的方法
- 安卓通过DHCP协议获取IP地址的过程
- 获取iPhone设备的IP的地址
- 获取iPhone设备的IP的地址
- Android获取移动设备的IP地址
- 获取android设备的IP地址
- python获取远程设备的IP地址
- SpringBoot入门-10(springboot配置freemarker模板)
- TextInputLayout的使用
- 自动释放linux内存
- python初学--用map规范英文名字
- MVP框架介绍
- 获取安卓设备上有线网或者无线网络的IP地址
- 开源测试报告框架-allure
- 自动生成.gitignore
- 三行代码,让你的桌面图标再也不会被打乱
- [游戏数据表]泰拉瑞亚Terraria 全物品合成表
- PostgreSQL 性能优化方法
- SSH免密登录问题
- mac快捷键
- 差分进化算法