
1、ping-ip
//创建连接 验证ip端口
public static boolean isReachableIp(String ipAddress) {
try {
InetAddress inetAddress = InetAddress.getByName(ipAddress);
if (inetAddress.isReachable(5000)) {
return true;
} else {
return false;
}
} catch (IOException e) {
return false;
}
}
2、telnet-端口
//创建连接 验证ip端口端口
public static boolean isReachable(String ipAddress, int port) {
try {
Socket socket = new Socket(ipAddress, port);
socket.close();
return true;
} catch (IOException e) {
return false;
}
}

1366

被折叠的 条评论
为什么被折叠?



