How do I do a reverse DNS lookup in Java?

I can see that there is an entry to reverse lookup a given IP using nslookup.

nslookup 54.193.201.195
Server:     172.16.0.23
Address:    172.16.0.23#53

Non-authoritative answer:
195.201.193.54.in-addr.arpa name = ec2-54-193-201-195.us-west-1.compute.amazonaws.com.

      

However, when I try to do the same thing in Java, using the approach outlined in multiple Stack Overflow answers, I keep getting the same input IP as the canonical hostname.

//Always prints the IP address I input
addr = InetAddress.getByName("54.193.201.195");
log.debug("Host Name: {}", addr.getCanonicalHostName());

      

How do I get the hostname record back instead of the same IP address I started with?

+3


source to share





All Articles