views:

131

answers:

3

HI I am writing an application where I need IP address. I have domain name, but I like to know hoe to get IP address from domain name. For ex www.girionjava.com how to get IP address of this by programming in java.

Thanks

+1  A: 
InetAddress.getByName("www.girionjava.com")
flybywire
+4  A: 
InetAddress giriAddress = java.net.InetAddress.getByName("www.girionjava.com");

Then, if you want the IP as a String

String address = giriAddress.getHostAddress();
R. Bemrose
A: 

(Extra mask in printing sine java considers all integers to be signed, but an IP address is unsigned)

InetAddress[] machines = InetAddress.getAllByName("yahoo.com");
for(InetAddress address : machines){
  byte[] ip = address.getAddress();
  for(byte b : ip){
    System.out.print(Integer.toString(((int)b)&0xFF)+".");
  }
  System.out.println();
}
M. Jessup
This assumes that you'll be getting only IPv4 adresses. IPv6 adresses are formatted differently, so you shouldn't manually format it anyway.
Joachim Sauer