1

I have been trying to write code in Java to do a DNS reverse lookup (look up hostname from given IP).

I have tried the following ways to do it.

InetAddress addr1 = InetAddress.getByName("11.121.5.67");
String host = addr1.getHostName();


byte[] ipAddr = new byte[] {(byte)34, (byte)195, (byte)110, (byte)15};  
host = InetAddress.getByAddress(ipAddr);
String hos = host.getCanonicalHostName();


Using org.xbill.DNS Library
lookup = new Lookup(ipaddress,Type.ANY);
Resolver resolver  = new SimpleResolver();
lookup.setResolver(resolver);
lookup.setCache(null);
Record[] records = lookup.run();


byte[] ipAddr = new byte[] {(byte)15, (byte)110, (byte)195, (byte)34};
Resolver res = new ExtendedResolver();
Name name = ReverseMap.fromAddress(ipAddr);
int type = Type.PTR;
int dclass = DClass.IN;
Record rec = Record.newRecord(name, type, dclass);
Message query = Message.newQuery(rec);
Message response = res.send(query);
Record[] answers = response.getSectionArray(Section.ANSWER);

But none of these options work. I am able to get the IP address from FQDN using InetAddress. But not reverse with any of the above options.

Should I setup the ResolverConfig or any other configuration before I use org.xbill.DNS for doing DNS Lookup?

Basically, I want to do DNSlookup in an organization level network systems.

I am a newbie to Java and these libraries. Any help would be greatly appreciated.

Micho
  • 3,929
  • 13
  • 37
  • 40

0 Answers0