Re: Reverse name resolution?
No, it CAN take an ip address as an argument, but this almost NEVER works with addresses other than local. You can store the ip address into a byte array, then use getByAddress() and pass it the byte array, then call getHostName on that InetAddress, and it will return the hostname...But again, that only works with localhosts...At least for me.
It would look something like this if it worked:
Code:
import java.net.*;
class testInet
{
public static void main(String[] args)
{
try
{
InetAddress ina = InetAddress.getByName("209.249.116.195");
byte[] b = new byte[]{(byte)209,(byte)249, 116, (byte)195);
InetAddress ina2 = InetAddress.getByAddress(b);
String hostname = ina2.getHostName();
System.out.println(hostname);
}
catch(UnknownHostException uhe)
{
uhe.printStackTrace();
}
}
}
I don't know of an easier way to get the bytes.
Re: Reverse name resolution?
Quote:
Posted by System_Error
You can store the ip address into a byte array, then use getByAddress() and pass it the byte array, then call getHostName on that InetAddress, and it will return the hostname...[/b]
Yes that would be the most logical thing to do. The problem is working with the byte array.
Code:
byte[] b = new byte[]{(byte)209,(byte)249, 116, (byte)195);
casting ints to bytes should produce negative numbers in all but 116. To me the whole thing is retarded. Bytes in an IP address are unsigned. Bytes in java are signed. Sun should make some unsinged types like C# has.
Re: Reverse name resolution?
That's what got me. I'm use to seeing that used in the context of local addresses. When you posed this question I thought about constructing it using a byte array. Once I started I realized why the ip address is almost always returned.