Linguagem Java

How to do a Ping from a machine to other in Java

import java.io.IOException;
import java.net.InetAddress;
 
public class Ping {
 
    private static void pingar(String host) {
        int delay=10000;
        boolean reachable=false;
        while(!reachable) {
          try {
            if (InetAddress.getByName(host).isReachable(delay)) {
              System.out.println("Ping OK: " + host);
              System.out.println(" - delay: " + delay);
              reachable = true;
            }
            else
                System.out.println(" - delay: " + delay);
          } catch (Exception e) {
            System.err.println("Ping FALHOU: " + host + " - " + e);
          }
          delay = delay+100;
        }
    }
 
    public static void main(String args[]) {
        //pingar("10.13.99.201");
        pingar("10.13.100.11");
        pingar("www.google.com");
    }
 
}
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.