wood burning stoves 2.0*
The moose likes Java in General and the fly likes help with InetAddress.getByAddress() ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "help with InetAddress.getByAddress() ?" Watch "help with InetAddress.getByAddress() ?" New topic

help with InetAddress.getByAddress() ?

Higgledy Smith
Ranch Hand

Joined: Mar 07, 2006
Posts: 192
I have an ip address, but need the hostname. To clarify, this is not the ip address of my localhost. I was thinking InetAddress.getByAddress(byte[] b) would do the trick. But several octets in the ip are greater than 127. For instance, (I made that up). I am thinking the people who designed this class would known this would be the case and have thought of a solution. Does anyone know how to get around the byte value limit? Thank you.
Vlado Zajac
Ranch Hand

Joined: Aug 03, 2004
Posts: 245
It works same way as reading/writing from/to files using byte arrays. This method uses byte as unsigned. will be this array:

2 middle elements will be negative but that is OK.

Or can use InetAddress.getByName which accepts IP address, too:
Higgledy Smith
Ranch Hand

Joined: Mar 07, 2006
Posts: 192
Thanks, Vlado Zajac. I would not have known getByName would take the ip as a string --the api does not saying anything about it. Thanks again.
I agree. Here's the link: http://aspose.com/file-tools
subject: help with InetAddress.getByAddress() ?
Similar Threads
list all machine name and ip addresses in LAN using java
NullPointerException when writing to a socket.
question regarding server socket if server socket is other machine
Listing all IP adresses on local network (LAN)
Socket not connected when using host ip address.