Monday, October 29, 2012

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


No comments:

Post a Comment