我使用以下代码:
Enumeration e = NetworkInterface.getNetworkInterfaces();
while(e.hasMoreElements()){
NetworkInterface n = (NetworkInterface) e.nextElement();
Enumeration ee = n.getInetAddresses();
while (ee.hasMoreElements()){
InetAddress i = (InetAddress) ee.nextElement();
System.out.println(i.getHostAddress());
}
}
但未列出我的机器IP。
cmd prompt -> ipconfig