import java.io.*;
import java.net.InetAddress;
import java.util.*;
public class Ip{
static public HashMap ping; //ping
后的结果集
public HashMap getPing(){ //
用来得到
ping
后的结果集
return ping;
}
//
当前线程的数量
,
防止过多线程摧毁电脑
static int threadCount = 1;
public Ip() {
ping = new HashMap();
}
public void Ping(String ip) throws Exception{
//
最多
30
个线程
while(threadCount>30)
Thread.sleep(50);
threadCount +=1;
PingIp p = new PingIp(ip);
p.start();
}
public void PingAll() throws Exception{
//
首先得到本机的
IP
,得到网段
InetAddress host = InetAddress.getLocalHost();
String hostAddress = host.getHostAddress();
System.out.println("
本机
IP
:
"+ hostAddress + "\n");
//test
int k=0;
k=hostAddress.lastIndexOf(".");
String ss = hostAddress.substring(0,k+1);
for(int i=1;i <=255;i++){ //
对所有局域网
Ip
String iip=ss+i;
System.out.println("
当前扫描
IP
:
"+ iip + "\n");
//test
Ping(iip);
}