Ping IP 求助!怎样用JAVA判断IP是否有通!!!返回值是true或false 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; public class TestPing { public static String testIP(String strip) { String message = null; Runtime runtime = Runtime.getRuntime(); Process process = null; String line = null; InputStream is = null; InputStreamReader isr = null; BufferedReader br = null; String ip = strip; try { // 根据CMD去PING IP process = runtime.exec("ping " + ip + " -w 1"); is = process.getInputStream(); isr = new InputStreamReader(is); br = new BufferedReader(isr); while ((line = br.readLine()) != null) { if ("Request timed out.".equals(line) || (line.length() > 3 && (line.trim() .indexOf("Ping request could not")) >= 0)) { message = "机器IP有错!"; } System.out.println(line); } br.close(); isr.close(); is.close(); } catch (IOException e) { e.printStackTrace(); } return message; } public static void main(String[] args){ String result=TestPing.testIP("192.168.0.100"); System.out.println(result); } } 那位做过snmp4j的开发的,怎么获取cpu,内存啊 tools.jar dt.jar rt.jar 分别是什么??? java学习方法 给JTextArea加滚动条问题 问个关于工资的问题 为什么 try 块没有执行? 请教一个Applet的问题 java输入输出问题 构造函数中的super如何获取类变量? openjdk和hotspot是不是一回事? JButton.setRolloverEnabled(false)为何不起作用? 请教一个webservice的问题
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
public class TestPing {
public static String testIP(String strip) {
String message = null;
Runtime runtime = Runtime.getRuntime();
Process process = null;
String line = null;
InputStream is = null;
InputStreamReader isr = null;
BufferedReader br = null;
String ip = strip;
try {
// 根据CMD去PING IP
process = runtime.exec("ping " + ip + " -w 1");
is = process.getInputStream();
isr = new InputStreamReader(is);
br = new BufferedReader(isr);
while ((line = br.readLine()) != null) {
if ("Request timed out.".equals(line)
|| (line.length() > 3 && (line.trim()
.indexOf("Ping request could not")) >= 0)) {
message = "机器IP有错!";
}
System.out.println(line);
}
br.close();
isr.close();
is.close();
} catch (IOException e) {
e.printStackTrace();
}
return message;
}
public static void main(String[] args){
String result=TestPing.testIP("192.168.0.100");
System.out.println(result);
}
}