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的结果,然后我怎么做。能给出代码最好
[code="java"]String line = "这里判断每一行是否包含TTL=64";
int type = 0;
if (line.indexOf("TTL") != -1) {
type = Integer.valueOf(line.substring(line.length() - 2,
line.length()));
switch (type) {
case 64: {
//这里你自己去看看TTL代表什么吧
break;
}
case 255: {
break;
}
default:
}
}[/code]
String line = "这里判断每一行是否包含TTL=64";
int type = 0;
if (line.indexOf("TTL") != -1) {
type = Integer.valueOf(line.substring(line.length() - 2,
line.length()));
switch (type) {
case 64: {
//这里你自己去看看TTL代表什么吧
break;
}
case 255: {
break;
}
default:
}
}
只知道本机的,不知道远程指定的机器的信息
[code="java"]
Runtime.getRuntime().exec("systeminfo");
[/code]