java中PING IP地址
2016-09-01 16:00
190 查看
public static void main(String [] args){
Runtime runtime = Runtime.getRuntime(); // 获取当前程序的运行进对象
Process process = null; // 声明处理类对象
String line = null; // 返回行信息
InputStream is = null; // 输入流
InputStreamReader isr = null; // 字节流
BufferedReader br = null;
String ip = "192.168.0.121";
boolean res = false;// 结果
try {
process = runtime.exec("ping " + ip); // PING
is = process.getInputStream(); // 实例化输入流
isr = new InputStreamReader(is);// 把输入流转换成字节流
br = new BufferedReader(isr);// 从字节中读取文本
while ((line = br.readLine()) != null) {
if (line.contains("TTL")) {
res = true;
break;
}
}
is.close();
isr.close();
br.close();
if (res) {
System.out.println("ping 通 ...");
} else {
System.out.println("ping 不通...");
}
} catch (IOException e) {
System.out.println(e);
runtime.exit(1);
}
}
Runtime runtime = Runtime.getRuntime(); // 获取当前程序的运行进对象
Process process = null; // 声明处理类对象
String line = null; // 返回行信息
InputStream is = null; // 输入流
InputStreamReader isr = null; // 字节流
BufferedReader br = null;
String ip = "192.168.0.121";
boolean res = false;// 结果
try {
process = runtime.exec("ping " + ip); // PING
is = process.getInputStream(); // 实例化输入流
isr = new InputStreamReader(is);// 把输入流转换成字节流
br = new BufferedReader(isr);// 从字节中读取文本
while ((line = br.readLine()) != null) {
if (line.contains("TTL")) {
res = true;
break;
}
}
is.close();
isr.close();
br.close();
if (res) {
System.out.println("ping 通 ...");
} else {
System.out.println("ping 不通...");
}
} catch (IOException e) {
System.out.println(e);
runtime.exit(1);
}
}
相关文章推荐
- java ping ip地址
- JAVA中Ping IP地址的两种方法
- 使用java简单模拟ping和telnet的实现
- 用JAVA程序取得IP地址
- java 实现ping功能
- 使用java简单模拟ping和telnet的实现
- 利用Java完成域名和IP地址的转换
- 用java得到机器的MAC,硬盘序列序列号和IP地址
- 实现获取主机名称,IP地址的类 (java)
- PING在IP地址冲突中的效果
- 使用java简单模拟ping和telnet的实现
- [j2se]利用JAVA获得IP地址的法子
- 用Java获得IP地址
- ping ip地址 通。显示pinging?挂在那(居然不是IP),还有机器内置喇叭报警(滴的一声)。
- 用Java获得IP地址
- java获取所有网卡和ip地址
- java获取本机的ip地址
- 用java得到本机所有的ip地址
- 实现获取主机名称,IP地址,MAC地址的类 (java)
- 用JAVA程序取得IP地址