Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to make reverse dns lookup in Java

I have a list of IPs. I need to make reveres DNS, i.e, I want the website name.

I tried the following:

InetAddress addr = InetAddress.getByName("98.138.253.109");
String host = addr.getCanonicalHostName();
System.out.println(host);

But, the IP in my example is for yahoo.com, when I run the code, I get: ir1.fp.vip.ne1.yahoo.com

I need a way so I can get the domain name by entering the IP.

like image 774
Wiliam A Avatar asked Feb 17 '23 16:02

Wiliam A


1 Answers

The IP Address in the code your provided resolves to yahoo because it is held by yahoo.

The Ip address you are using is designated for only one host. As you can imagine yahoo probably has thousands of servers. They get assigned an allocation of ipaddresses which they then reuse as they see fit for internal allocation. The different servers under yahoo domain have different names and hence when you reference an ip address from a specific server you get the name for that specific server. For the general ipaddress for yahoo.com that might be hidden unless you want to to a nslookup and query a whole range of ipaddress to find yahoo.com allocations and generalize from there.

like image 189
myqyl4 Avatar answered Feb 27 '23 00:02

myqyl4