查局域网在线的机子

chenzhehui chenzhehui 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

import java.net.* ;

class Scanner extends Thread
{
String ip ;
int port ;
Scanner(String ip, int port)
{
this.ip=ip ;
this.port=port ;
}

public void run()
{
try
{
Socket so=new Socket(ip,port) ;
System.out.println(this.ip+"--->"+this.port) ;
}
catch(Exception ex)
{
System.out.println(ip+"is not found"+ex) ;
}
}
};
class Test
{
public static void main(String[] args)
{
String ip="192.168.1." ;
int port=80 ;
System.out.print("请输入你要测试的端口:") ;
try
{
port=System.in.read() ;
}
catch(Exception ex)
{
System.out.println(ex) ;
}


for(int i=1 ;i<255 ;i++)
{
Scanner sc=new Scanner(ip+i,port) ;
sc.start() ;
}
}
};

我想知道我用这种方法有效么?
各位帮帮忙,给点意见吧.
...全文
评论 7
收藏 已收藏
分享
返回顶部
chenzhehui
Java SE 62,621 成员 307,251 内容