Resolving a subnet to a specific domain

Dan asked:

I am trying to figure out how to resolve a subnet for a specific domain on my CentOS machine. for example Google owns a range of IP addresses and one range in particular is - Now they also have many more but I will just talk about this range for the question.

What I was originally trying to do was have this range in the /etc/hosts file with the hostname Google, but I found out that the /etc/hosts file only takes one IP address per line and not a range of IP addresses or even accepting wildcards.

The reason for the importance on this is we have a product that tracks IP addresses users visit and we want to chart the data on a tree map, but instead of the chart showing we want it to display Google.

The only lead I have so far is using the /etc/hosts file but I do not want to single handily type out every single address for Google, then Facebook and so on. Is there another way I could achieve my goal, making life a lot easier for me?

My answer:

I think you could easily query RADb for this. Get the ASN for each IP address, and just work with those.

For example:

$ whois -h
descr:              Qwest Communications
                    950 17th Street Suite 1900
                    Denver, CO 80202
origin:             AS209
mnt-by:             MAINT-QWEST
changed:   20020504
source:             RADB

Here we see that this IP is in AS209 (which you can store instead of the IP, or in addition to it, if you wish) and is registered to Qwest Communications, which you can then display.

View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.