Monday, October 29, 2012

Get Routing IP Address of a Domain In java

Normally if you ping a domain www.google.com from command prompt it doesn't directly reach the server from your location they might have a local server inside your country from there it will take several routes and reach the main server

For example : 
Google taken 5 hops when i ping from my local system :
www.google.com/74.125.236.52

www.google.com/74.125.236.49
www.google.com/74.125.236.51
www.google.com/74.125.236.50
www.google.com/74.125.236.48

To determine the hops here is the source code in java :


import java.net.*;

class GetAllHops {

  public static void main(String args[]) {

    try {
      InetAddress[] addresses = InetAddress.getAllByName("www.google.com");
      for(int i = 0; i < addresses.length; i++) {
        System.out.println(addresses[i]);
      }
    } catch(UnknownHostException e) {
      System.out.println("Could not find www.apple.com");
    }

  }

}



No comments:

Post a Comment