diff options
Diffstat (limited to 'java')
| -rw-r--r-- | java/Ping.java | 26 | 
1 files changed, 26 insertions, 0 deletions
diff --git a/java/Ping.java b/java/Ping.java new file mode 100644 index 0000000..8e88261 --- /dev/null +++ b/java/Ping.java @@ -0,0 +1,26 @@ + +import java.io.IOException; +import java.net.UnknownHostException; +import java.net.InetAddress; + +public class Ping { + +    public static void tryPing(String ipAddress) +    { +        boolean reachable = false; +        try { +            InetAddress inet = InetAddress.getByName(ipAddress); +            reachable = inet.isReachable(5000); +        } +        catch (UnknownHostException e) {} +        catch (IOException e) {} +        System.out.println(ipAddress + " is " + (reachable ? "is reachable" : "is NOT reachable")); +    } + +    public static void main(String[] args) throws UnknownHostException, IOException +    { +        tryPing("127.0.0.1"); +        tryPing("asynk.ch"); +        tryPing("asynk.cc"); +    } +}  | 
