public static void main(String[] args) throws SocketException {
Enumeration<NetworkInterface> enumeration = NetworkInterface
.getNetworkInterfaces();
while (enumeration.hasMoreElements()) {
NetworkInterface networkInterface = enumeration.nextElement();
if (networkInterface.isUp()) {
System.out.println(networkInterface.getDisplayName());
Enumeration<InetAddress> addressEnumeration = networkInterface
.getInetAddresses();
while (addressEnumeration.hasMoreElements()) {
System.out.println("\t" + addressEnumeration.nextElement());
}
}
}
}
获取本机所有IP地址
最新推荐文章于 2022-04-01 17:29:35 发布