日期:2014-05-20 浏览次数:20784 次
public class Test {
public static void main(String[] args) {
int ips[] = new int[] { 192, 168, 85, 0 };
for (int i = 1; i < 255; i++) {
String ip = ips[0] + "." + ips[1] + "." + ips[2] + "." + i;
while (!runPT(ip)) {
try {
Thread.sleep(10);
} catch (Exception e) {
}
}
// System.out.println("start "+ip);
}
}
public static class PingThread extends Thread {
private String ip;
private boolean running;
public String getIp() {
return ip;
}
public void setIp(String ip) {
this.ip = ip;
}
public boolean isRunning() {
return running;
}
public void setRunning(boolean running) {
this.running = running;
}
public PingThread() {
}
@Override
public void run() {
while (true) {
synchronized (this) {
// running = true;
try {
if (ip != null) {
String cmd = "ping -c 4 " + ip;
String key = "bytes from " + ip;
// System.out.println(cmd);
boolean pingok = false;
java.lang.Process p = java.lang.Runtime
.getRuntime().exec(cmd);
java.io.InputStream is = p.getInputStream();
java.io.BufferedReader br = new java.io.BufferedReader(
new java.io.InputStreamReader(is));