✸ ✸ ✸
java查询当前广播域在线主机及主机名,不是多线程速度很慢,另外isReachable设置低于2000就会返回false,目前原因未知。。慢慢学习。。
import java.net.*;
import java.util.*;
class PingNet
{ public static void main(String[] args)
{
try{
int count=0;
for(int i=1;i< ibr> String host="192.168.0."+i;
InetAddress target=InetAddress.getByName(host);
if(target.isReachable(3000)){
count++;
System.out.println("发现"+ count+ "主机在线,"+"IP是"+target.getHostAddress()+",主机名是"+target.getHostName());}
}}catch (Exception ex){
ex.printStackTrace();}
}
}
✸ ✸ ✸
📜 版权声明
本文作者:王梓 | 原文链接:https://www.bthlt.com/note/10377840-Javajava查询当前广播域在线主机及主机名
出处:葫芦的运维日志 | 转载请注明出处并保留原文链接


📜 留言板
留言提交后需管理员审核通过才会显示