java安卓ping IP 测试IP网络是否通畅
java安卓ping IP 测试IP网络是否通畅
public static void sendPingRequest(String ipAddress) throws UnknownHostException, IOException { InetAddress geek = InetAddress.getByName(ipAddress); System.out.println("Sending Ping Request to " + ipAddress); if (geek.isReachable(5000)) { System.out.println("Host is reachable"); } else { System.out.println("Sorry ! We can't reach to this host"); } } // Driver code public static void main( String[] args ) throws UnknownHostException, IOException { String ipAddress; Scanner sc = new Scanner(System.in); System.out.println("Enter ipAddress"); ipAddress = sc.next(); sendPingRequest(ipAddress); }
欢迎讨论,相互学习。
cdtxw@foxmail.com