120
11-24-2009, 07:14 PM
Hi - I've had a look around for places where I can get some help/advice on a Java issue I have? I've tried usenet but the groups look almost dead(?). Coding Forums has come highly recommended.
I'm new to Java, but have some general programming and shell experience. I was pleasantly surprised to find how quick and easy it is to get working code out of Java - but I'm struggling with DNS lookups.
Basically, I'm trying to mimic a reverse dns lookup (ip to full PTR) like I would get with:
dig -x 211.21.152.4
or
host 211.21.152.4
This code works-ish:
import java.net.*;
//.......
try {
InetAddress thost = InetAddress.getByName("211.21.152.4");
//HostName = thost.getHostName();
HostName = thost.getCanonicalHostName();
System.out.println("HOST: "+HostName);
} catch (UnknownHostException e) {
System.out.println("NO HOST");
}
NOTE: tried thost.getCanonicalHostName & getHostName
The issue I'm getting is the result is not consistent with DNS.
This code returns: HOST: 211.21.152.4
but, dig -x 211.21.152.4 returns
211-21-152-4.HINET-IP.hinet.net
AND
host 211.21.152.4 returns:
211-21-152-4.HINET-IP.hinet.net.
At first I thought the methods getHostName/getCanonicalHostName were returning what it thought was the hostname from the string, and it was extremely intelligent in finding this name. I also noted the docs warned that if there was a security manager in place, 'a textual representation of the IP address would be returned'. That was fine until I tried the code again with 80.75.69.195 and the Java code returned the full PTR as dig -x or host would:
HOST: web1.redut.net
Basically it appears that if the DNS PTR contains something that looks like an IP address, the Java methods are returning it rather than the whole pointer.
What I want is the whole pointer line from a reverse DNS lookup. I know there is an xbill dns library, but my concern is - assuming I can figure out how to install it - this will make what I am writing less portable(?) and require target JVM to have the library. I would really like to keep it to the core libraries at this stage.
Does anyone know what I can do to get the full pointer, regardless of if parts of it *look* like an IP? Any help or pointers to other places to ask would be really appreciated.
I know it must irritate regular posters here when someone new bursts in, asks a question, gets an answer and never contributes again. I promise not to do that now that I've found this forum.
Mike
I'm new to Java, but have some general programming and shell experience. I was pleasantly surprised to find how quick and easy it is to get working code out of Java - but I'm struggling with DNS lookups.
Basically, I'm trying to mimic a reverse dns lookup (ip to full PTR) like I would get with:
dig -x 211.21.152.4
or
host 211.21.152.4
This code works-ish:
import java.net.*;
//.......
try {
InetAddress thost = InetAddress.getByName("211.21.152.4");
//HostName = thost.getHostName();
HostName = thost.getCanonicalHostName();
System.out.println("HOST: "+HostName);
} catch (UnknownHostException e) {
System.out.println("NO HOST");
}
NOTE: tried thost.getCanonicalHostName & getHostName
The issue I'm getting is the result is not consistent with DNS.
This code returns: HOST: 211.21.152.4
but, dig -x 211.21.152.4 returns
211-21-152-4.HINET-IP.hinet.net
AND
host 211.21.152.4 returns:
211-21-152-4.HINET-IP.hinet.net.
At first I thought the methods getHostName/getCanonicalHostName were returning what it thought was the hostname from the string, and it was extremely intelligent in finding this name. I also noted the docs warned that if there was a security manager in place, 'a textual representation of the IP address would be returned'. That was fine until I tried the code again with 80.75.69.195 and the Java code returned the full PTR as dig -x or host would:
HOST: web1.redut.net
Basically it appears that if the DNS PTR contains something that looks like an IP address, the Java methods are returning it rather than the whole pointer.
What I want is the whole pointer line from a reverse DNS lookup. I know there is an xbill dns library, but my concern is - assuming I can figure out how to install it - this will make what I am writing less portable(?) and require target JVM to have the library. I would really like to keep it to the core libraries at this stage.
Does anyone know what I can do to get the full pointer, regardless of if parts of it *look* like an IP? Any help or pointers to other places to ask would be really appreciated.
I know it must irritate regular posters here when someone new bursts in, asks a question, gets an answer and never contributes again. I promise not to do that now that I've found this forum.
Mike