is IP Reachable - Java Network

Java examples for Network:Ping

Description

is IP Reachable

Demo Code


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

public class Main {

    public static boolean isReachable(String ip, int timeout) {
        try {// www  .ja v  a  2 s .c o  m
            InetAddress address = InetAddress.getByName(ip);
            return address.isReachable(timeout);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }

    public static boolean isReachable(String ip) {
        return isReachable(ip, 5000);
    }
}

Related Tutorials