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
java dns


source to share


No one has answered this question yet

Check out similar questions:

6170
Is Java "pass-by-reference" or "pass-by-value"?
3799
How do I read / convert an InputStream to a string in Java?
3324
How to generate random integers in a specific range in Java?
3073
How to efficiently loop over each entry in a Java map?
3044
Making a memory leak with Java
2956
What is the difference between public, secure, batch and private in Java?
2936
When to use LinkedList over ArrayList in Java?
2853
How can I convert String to int in Java?
2171
How to determine if an array contains a specific value in Java?
2108
How can I call one constructor from another in Java?



All Articles
Loading...
X
Show
Funny
Dev
Pics