我正在寻找一种更好的方法来使用 Java 在我的 LAN 网络中获取计算机名称。我努力了:
byte[] ip = {(byte)192,(byte)168,(byte)178,(byte)1};
for(int i=1;i<255;i++)
{
ip[3] = (byte)i;
try
{
InetAddress addr = InetAddress.getByAddress(ip);
String s = addr.getHostName();
System.out.println(s);
}
catch(UnknownHostException e)
{
System.out.println(e.getMessage());
}
}
……但是太慢了。还有其他方法吗?
我在 Windows 上。
任何想法表示赞赏。