package com;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
public class TimerExecPing {
/**
* @param args
*/
public static void ping(final String host) {
String system = (String) (System.getProperty("os.name")).toLowerCase();
String command = "";
if (system.indexOf("xp") != -1 || system.indexOf("win") !=-1) {
command += "ping win " + host;
System.out.println(command);
} else if (system.indexOf("linux") != -1) {
command += "ping linux" + host;
System.out.println(command);
} else {
command += "ping " + host;
System.out.println(command);
}
TimerTask timerTask = new TimerTask() {
public void run() {
Process process;
try {
process = Runtime.getRuntime().exec("ping " + host);
String result = "";
BufferedReader input = new BufferedReader(
new InputStreamReader(process.getInputStream(),
"gbk"));
String line;
while ((line = input.readLine()) != null) {
result += line;
// result=line.split(" ");
System.out.println(line);
}
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
};
Timer timer = new Timer();
timer.schedule(timerTask, new Date());
}
public static void main(String[] args) {
TimerExecPing pi=new TimerExecPing();
pi.ping("200.1.1.60");
}
}
图为通过ping ip的结果,然后我怎么做。能给出代码最好