diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2017-02-16 12:26:59 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2017-02-16 12:26:59 +0100 |
commit | 348663665082107181968a76fd14c2491b4f51e2 (patch) | |
tree | a6baf6fa023192e715ec823d13767e1c4d86446c /java | |
parent | 7a05de6820fa7d50a69a207ea25b81de8d0d9b87 (diff) | |
download | share-348663665082107181968a76fd14c2491b4f51e2.zip share-348663665082107181968a76fd14c2491b4f51e2.tar.gz |
java : add Ping.java
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"); + } +} |