ping a Host - Java Network

Java examples for Network:Ping

Description

ping a Host

Demo Code


//package com.java2s;
import java.net.InetAddress;

public class Main {
    public static boolean ping(String host, int connectTimeOut) {
        InetAddress address;//from w w w  .  j a  va2 s. c om
        try {
            address = InetAddress.getByName(host);
            return address.isReachable(connectTimeOut);
        } catch (Exception e) {
            return false;
        }
    }
}

Related Tutorials