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);
        }

 

posted @ 2023-09-26 08:38  txwtech  阅读(97)  评论(0编辑  收藏  举报