Java Utililty Methods InetAddress Ping

List of utility methods to do InetAddress Ping

  1. HOME
  2. Java
  3. I
  4. InetAddress Ping

Description

The list of methods to do InetAddress Ping are organized into topic(s).

Method

boolean ping(InetAddress addr, NetworkInterface ni)
ping
return ping(addr, ni, 255, 5000);
boolean ping(InetAddress host)
Method taken from http://stackoverflow.com/questions/2448666/how-to-do-a-true-java-ping-from-windows
try {
 String cmd = "";
 if (System.getProperty(SYSTEM_PROPERTY_OS_NAME).toLowerCase().startsWith(OS_NAME_WINDOWS)) {
 cmd = WINDOWS_PING_CMD + host.getHostAddress();
 } else {
 cmd = UNIX_PING_CMD + host.getHostAddress();
 Process myProcess = Runtime.getRuntime().exec(cmd);
...
int ping(InetAddress target)
Get the answer time of the host
return ping(target, 300);
boolean pingFromLocalAddress(InetAddress localAddr)
ping From Local Address
boolean connected = false;
Socket socket = null;
try {
 socket = new Socket(IPv6_ONLY_SERVER_IP, IPv6_ONLY_SERVER_PORT, localAddr, 0);
 out.println("Created!");
 connected = true;
} catch (IOException e) {
 out.println("Failed to connect");
...
boolean pingUsingInetAddress()
ping Using Inet Address
try {
 return InetAddress.getByName("4.2.2.2").isReachable((int) TimeUnit.SECONDS.toMillis(15));
} catch (Exception e) {
 return false;
long pingWindows(InetAddress address, long timeout)
ping Windows
boolean reached = false;
long start = System.currentTimeMillis();
long end = (start - 1);
try {
 String line;
 ProcessBuilder processBuilder = new ProcessBuilder(
 new String[] { "ping", address.getHostAddress(), "-w", String.valueOf(timeout), "-n", "1" });
 Process process = processBuilder.start();
...
int ping(final InetAddress address)
ping
Long start = System.currentTimeMillis();
try {
 if (!address.isReachable(2000))
 return -1;
 return (int) (System.currentTimeMillis() - start);
} catch (IOException ex) {
 return -1;


AltStyle によって変換されたページ (->オリジナル) /