try { Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); while (interfaces.hasMoreElements()) { NetworkInterface iface = interfaces.nextElement(); if (iface.isLoopback() || !iface.isUp()) { continue; } Enumeration<InetAddress> addresses = iface.getInetAddresses(); while (addresses.hasMoreElements()) { InetAddress addr = addresses.nextElement(); if (addr instanceof Inet6Address) { continue; } ip = addr.getHostAddress(); } } } catch (SocketException e) { LoggerUtils.error(String.format("获取本机IP异常:%s", e.getStackTrace()), null); ip = "127.0.0.1"; }
转载于:https://www.cnblogs.com/chinaifae/p/10239315.html
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/101192.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...