获取我的局域网IP地址(192.168.xxxx)(IPV4)

获取我的局域网IP地址(192.168.xxxx)(IPV4),第1张

获取我的局域网IP地址(192.168.xxxx)(IPV4)
public static String getIpAddress() {  try {     for (Enumeration en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {         NetworkInterface intf = en.nextElement();         for (Enumeration enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {  InetAddress inetAddress = enumIpAddr.nextElement();  if (!inetAddress.isLoopbackAddress()&&inetAddress instanceof Inet4Address) {      String ipAddress=inetAddress.getHostAddress().toString();      Log.e("IP address",""+ipAddress);      return ipAddress;  }         }     } } catch (SocketException ex) {     Log.e("Socket exception in GetIP Address of Utilities", ex.toString()); } return null;     }

授予权限

还添加mainfest。

<uses-permission android:name="android.permission.INTERNET" /><uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5616047.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-15
下一篇 2022-12-15

发表评论

登录后才能评论

评论列表(0条)

保存