/*
* Scans IP networks using ping
* Substitute your target net address in String net
* by Paul Chin, Feb 9, 2009
*/
package ipscanner;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class IPScanner {
public static void main(String[] args) throws InterruptedException {
IPScanner ips = new IPScanner();
ips.doScan();
}
private void doScan() throws InterruptedException {
Thread[] t = new Thread[255];
MyScanner[] ms = new MyScanner[255];
String net = "118.100.118.";
for (int i = 1; i < 255; i++) {
ms[i] = new MyScanner(net + i);
t[i] = new Thread(ms[i]);
t[i].start();
Thread.sleep(100);
}
}
}
class MyScanner implements Runnable {
String ip;
public MyScanner(String ip) {
this.ip = ip;
}
public void run() {
try {
String line;
Process p = Runtime.getRuntime().exec("cmd /c ping " + ip + " -n 1");
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
while ((line = input.readLine()) != null) {
if (line.indexOf("Reply") > -1) {
System.out.println(line);
}
}
input.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}