reverse DNS lookup

Posted on 2004-12-01
Last Modified: 2010-03-05
We're using now gethostbyaddr for reverse DNS lookup to process site logs. It fails for quite a lot of them, though. Is there any other way to find out the domain names? And is there a way to find out a country of origin for a .com domain?
Question by:jgenyuk
    LVL 13

    Accepted Solution

    Are these valid failures? Some IP addresses do not have PTR records.

    You might want to look into GeoIP for determining geographical locations of IP addresses. There are several modules on for this. Here's one for example:

    Author Comment

    Thanks for the module link, is it better than IP::Country or are tehy pretty much the same?

    I'm not sure what "valid failures" are, I mean IPs that couldn't be resolved. Here's the code.

    ($name,$aliases,$addrtype,$length,@addrs) =
        # return the ip number if the name is unresolvable
        $name = $ipnum if(!defined($name));

    Expert Comment

    Well, they are all the same! But coded differently, an ant could walk better then others, but it still walks!

    Well, I don't think so, and they don't work for server logs, as they are old, most of people have DSL internet, means, dynamic IP address's, and while he disconnected, and that slot is free, means, that IP equals nothing at all! You could sort of do that process at the same time a user joins

    My first post, Hope it helped!
    LVL 13

    Expert Comment


    I mean have you seen IPs that couldn't be resolved by your script but _could_ be resolved manually.. (using dig or nslookup or similar) It's likely that the IPs you're seeing not resolve just simply don't have any PTR records defined and hence will not resolve (rightfully so).

    Expert Comment

    Weird, Well, You could maybe rebuild the way it does nslookup, or maybe sniff

    Can you post a packet sniff part of nslookup? So I could re-implement that into a function and hand it to you :-)
    LVL 48

    Expert Comment

    There are *so* many DNS setups on the Internet that are badly configured or just plain wrong, so not being able to resolve IP addresses is *very* common.

    GeoIP is supposed to be less portable than IP::Country.  Apart from that, they appear to be pretty similar.


    Author Comment

    Actually I've tried some of these IPs and quite a few of them were resolved by dig (but not nslookup).

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Suggested Solutions

    I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
    In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    730 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now