使用java来ping主机
来源:互联网 发布:开一家淘宝网店 编辑:程序博客网 时间:2024/05/20 14:40
测试连通性的工具类。
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Ping {
/**
* 方法名称 :ping
* 创 建 人:wumanxin
* 功能说明 :连接主机
* @return 返回连接的状态
*/
public static boolean ping(String ipAddress) throws Exception {
int timeOut = 3000 ; //超时应该在3钞以上
boolean status = InetAddress.getByName(ipAddress).isReachable(timeOut); // 当返回值是true时,说明host是可用的,false则不可。
return status;
}
/**
* 方法名称 :main
* 创 建 人:wumanxin
* 功能说明 :用于测试是否可以ping通
* @return
*/
public static void main(String[] args) throws Exception {
String ipAddress = "www.baidu.com";
System.out.println(ping(ipAddress));
}
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Ping {
/**
* 方法名称 :ping
* 创 建 人:wumanxin
* 功能说明 :连接主机
* @return 返回连接的状态
*/
public static boolean ping(String ipAddress) throws Exception {
int timeOut = 3000 ; //超时应该在3钞以上
boolean status = InetAddress.getByName(ipAddress).isReachable(timeOut); // 当返回值是true时,说明host是可用的,false则不可。
return status;
}
/**
* 方法名称 :main
* 创 建 人:wumanxin
* 功能说明 :用于测试是否可以ping通
* @return
*/
public static void main(String[] args) throws Exception {
String ipAddress = "www.baidu.com";
System.out.println(ping(ipAddress));
}
}
阅读全文
1 0
- 使用java来ping主机
- 用 ping 来查看主机的系统
- Zabbix中使用ICMP ping来判断主机是否存活的问题
- 使用批处理ping ip段内主机
- 使用C#ping主机的方法
- 使用C#PING主机的方法
- 通过java ping 各个主机的连通性
- 使用playbooks来ping主机时显示"Using a SSH password instead of a key is not possible
- 使用 ShellExecute 来进行 Ping 操作!
- 使用 ShellExecute 来进行 Ping 操作!
- Java学习篇之--检测主机是否在线Ping
- 主机ping不通虚拟机
- ping主机的脚本
- Ping无法访问目标主机
- uboot ping不通主机
- ping无法访问目标主机
- 虚拟机ping不通主机
- 虚拟机ping不通主机
- Test_Java_网络编程(客户端向服务器发送字符串,服务器将字符串反转后发送给客户端)
- 【机器学习详解】SMO算法剖析
- 颠覆式前端UI开发框架:React
- 索引优化示例详解
- 10个Utils包
- 使用java来ping主机
- 线性代数 -- 行列式公式和代数余子式
- Failed to start component,A child container failed during start
- Sublime Text2中的快捷键
- 随机获取文件夹下图片
- Unity3D 通用动作
- 【21】Bootstrap — 徽章
- 数据库中的左连接和右连接
- JAVA多线程