blob: 8e882613c0c58805cc2239c0b992761beffb65da (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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");
}
}
|