Java Host Ping Ping(String host, int timeout)

Here you can find the source of Ping(String host, int timeout)

Description

Tes apakah host/IP bisa dihubungi

License

Open Source License

Parameter

Parameter Description
String host String Nama host / IP

Declaration

public static void Ping(String host, int timeout) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.IOException;

import java.net.InetAddress;

import java.net.UnknownHostException;

public class Main {
    /**/*from  w  w w .j av  a 2 s . c  o m*/
     * Tes apakah host/IP bisa dihubungi
     * @param String host String Nama host / IP
     * @param int timeout Batas waktu (dalam milidetik)
     */
    public static void Ping(String host, int timeout) {
        try {
            if (InetAddress.getByName(host).isReachable(timeout)) {
                System.out.printf("%s is reachable %n", host);
            } else {
                System.out.printf("%s is unreachable %n", host);
            }

        } catch (UnknownHostException ex) {
            System.out.printf("Unknown host: %s%n", host);
        } catch (IOException ex) {
            System.out.println(ex);
        }

    }
}

Related

  1. ping(final String host, final int timeout)
  2. ping(String host)
  3. ping(String host, int timeout)
  4. ping(String host, int timeout)
  5. ping(String host, int timeout)