Showing posts with label InetAddress. Show all posts
Showing posts with label InetAddress. Show all posts

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");
    }

  }

}



IP Address Of Domain in Java


How Do you get the IP Address of the domain in java  : 


The Domain Name System (DNS) is a hierarchical distributed naming system for computers, services, or any resource connected to the Internet or a private network. It associates various information with domain names assigned to each of the participating entities. A Domain Name Service resolves queries for these names into IP addresses for the purpose of locating computer services and devices worldwide. By providing a worldwide, distributed keyword-based redirection service, the Domain Name System is an essential component of the functionality of the Internet.
An often-used analogy to explain the Domain Name System is that it serves as the phone book for the Internet by translating human-friendly computer hostnames into IP addresses. For example, the domain name www.example.com translates to the addresses 192.0.43.10 (IPv4) and 2620:0:2d0:200::10 (IPv6). Unlike a phone book, however, DNS can be quickly updated and these updates distributed, allowing a service's location on the network to change without affecting the end users, who continue to use the same hostname. Users take advantage of this when they recite meaningful Uniform Resource Locators (URLs) and e-mail addresses without having to know how the computer actually locates the services.
Know More About DNS : Click Here
For example IP of  www.Google.com 

Source Code :

import java.net.*;

class GetAddressOfDomain {
  public static void main(String args[]) {

    try {
      InetAddress address = InetAddress.getByName("www.google.com");
      System.out.println(address);
    } catch(UnknownHostException e) {
      System.out.println("Could not find www.google.com");
    }

  }

}

Console : www.google.com/74.125.236.50