Check web domain availability using python-whois
In this post, I am going to show you, how you can use python to check domain availability rather to go to godaddy.com or any other domain lookup website to make this check. Oh yeah that means you can use this to find out the available domains too. Well lets get started.
First of all you need to install python-whois. You can do this using your favorite tool pip. Its just a single step.
pip install python-whoisto verify that python-whois is installed its even more easy.
python -c 'import whois'Successful installation means you get no errors running the above command. If you get 'No module named whois' then this means you are installation wasn't successful.
Not that python-whois installed, we are ready to start using it. Lets do it by not saving in a file but opening python interactive shell and explore. To open python open terminal and hit enter after typing python. You should be in the python interactive mode
>>> import whoisIf you saw something like this, no output at all then the domain exists. we will now see what information we can get about the domain in a while. And if you saw something like below, then that means the domain is available.
>>> result=whois.whois('merosanokatha.com')
>>>
Traceback (most recent call last):Ok, so lets see what information is available from the existing domains
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/site-packages/whois/__init__.py", line 20, in whois
return WhoisEntry.load(domain, text)
File "/usr/lib/python2.7/site-packages/whois/parser.py", line 101, in load
return WhoisCom(domain, text)
File "/usr/lib/python2.7/site-packages/whois/parser.py", line 134, in __init__
raise PywhoisError(text)
whois.parser.PywhoisError:
Whois Server Version 2.0
Domain names in the .com and .net domains can now be registered
with many different competing registrars. Go to http://www.internic.net
for detailed information.
No match for "MEROSAPANAADHYAO.COM".
>>> result.attrs() # lists the attributes of resultSimilary other attributes can be obtained like result.updated_date, result.expiration_date, result.whois_server, result.status and so on. For more detail information you can use result.text.
>>> ['creation_date', 'domain_name', 'emails', 'expiration_date', 'name_servers', 'referral_url', 'registrar', 'status', 'updated_date', 'whois_server']
>>> result.creation_date #gets the registration date
datetime.datetime(2011, 10, 26, 0, 0)
Well this is how you can use python-whois module. A small tweaking can help you obtain related unavailable domains.
Happy PyPy-ing
Good source.
ReplyDeleteI am glad that it was helpful to you.
Delete