【发布时间】:2015-11-20 09:38:46
【问题描述】:
我制作了一个简单的程序来扫描我的网络 IP 并列出所有可用的设备:
InetAddress localhost = InetAddress.getLocalHost();
byte[] ip = localhost.getAddress();
ip[3] = (byte) x;
InetAddress address = InetAddress.getByAddress(ip);
if (!address.getHostAddress().equals(address.getHostName())) {
avilablePcsList.add(address);
System.out.println(address.getHostName() + "\t" + address.getHostAddress() + "\t" + NetworkInterface.getByInetAddress(address));
}
但是这段代码获得了我网络上除我的计算机之外的所有可用设备,那么为什么这段代码没有显示我的计算机?以及如何显示它?
BTW:x 是 for 循环的计数器变量(1:254)
【问题讨论】:
标签: java network-programming ip scanning