Search code examples
python-2.7dnswhoisconnection-refused

Gathering DNS whois information for large number of typo/squatting domain names


I am going to gather and analyze the DNS registration information of a large number of domain names. My domain names are such as bbc.com, bbc.com.co, bbc.com.a and bbc.com.aa. As you can see, I have typo/squatting domain names of the official web sites such as bbc.com. I am using python whois library and send DNS whois query to these domain names, but for so many of them, I got below message: Here is my code for sending whois query :

try:
    typo_dns_info = whois.whois(typo)
    if typo_dns_info:
        typo_info[typo] = typo_dns_info
        registered_typo.append(typo)
except:
    pass

and I got this error for many of the domain names:

Socket Error: [Errno 111] Connection refused

I searched and I think maybe I need to sleep my program to send DNS query after 1 second. But it did not help me at all. I do not know what is the best way to get the whois information of a url?


Solution

  • I use regular DNS queries to tell if a domain exists. Whois servers typically aren't set up for high volume queries and some limit the rate of queries on a per-IP basis. Regular DNS servers are designed for high lookup rates and will not throw the same errors.

    Here's a bit of code to discover registered domains via dnspython:

    try:
        dns.resolver.query(typo, 'A')
        print("%s exists" % typo)
    except:
        try:
            x = whois.whois(typo)
            print("%s exists" % typo)
        except:
            print("%s doesn't exist" % typo)