InetAddress and IP-addresses
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Zeta_Kouper
Posted On:   Thursday, May 26, 2005 11:12 AM


Hi!Pleaseanyone who can answer my question!!


Do you know how I can construct an InetAddress object in Java using the IP-address of a host in the format :


e.g. 176.101.102.67


There is no way to do that in the java.net.InetAddress API.


I have to use the host name as a String or the ip address


as a byte array, but 147 for example exceeds the limits


of the MAX_VALUE for a byte.


Thank you very much!!

Re: InetAddress and IP-addresses

Posted By:   Anonymous  
Posted On:   Tuesday, June 14, 2005 10:33 PM

I don't think there is a way to get the ip address as an array of bytes(to be used to create a InetAddress object using getByAddress(byte[] b)) other than using the byte[] getAddress() method.

InetAddress inet = InetAddress.getByName("www.sun.com");
System.out.println(inet.getHostName());
System.out.println(inet.getHostAddress());
InetAddress inet2 = InetAddress.getByAddress(inet.getAddress());
System.out.println(inet2.getHostName());
System.out.println(inet2.getHostAddress());
About | Sitemap | Contact