Here you can find the source of Ping(String host, int timeout)
Parameter | Description |
---|---|
String | host String Nama host / IP |
public static void Ping(String host, int timeout)
//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); } } }