Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check whether domain is registered

Tags:

I'm trying to make a script that returns unregistered domains. I'm working in Python 2.7. I've read that the module whois should be able to do that but the code I've written raises an error.

Code:

import whois domains = ['http://www.example.com']  for dom in domains:     domain = whois.Domain(dom)     print domain.registrar  

Error:

  domain = whois.Domain(dom)   File "C:\Python27\lib\site-packages\whois\_3_adjust.py", line 12, in __init__     self.name               = data['domain_name'][0].strip().lower() TypeError: string indices must be integers, not str 

Have you any idea what could be wrong? Or can you give me a better solution?

EDIT: I tried the pythonwhois module but it returns an error too.

EDIT2: According to one solution here, on SO, I've tried to use pywhois, this code raises an error too.

import pywhois w = pywhois.whois('google.com') w.expiration_date 

ERROR:

w = pywhois.whois('google.com') AttributeError: 'module' object has no attribute 'whois' 
like image 558
Milano Avatar asked Apr 21 '15 13:04

Milano


People also ask

How do you check if a domain is registered?

Navigate to https://domains.google.com/registrar. Enter your preferred domain name in the search box. Review the search results to determine if the domain is available.

How can I check my domain status?

Go to lookup.icann.org. In the search field, enter your domain name and click Lookup. In the results page, scroll down to Registrar Information. The registrar is usually your domain host.

Whats is my domain?

To find the Domain for your computer: For Windows machines, click on the Start Menu, go to Control Panel, System and Security, then System. You'll see your computer's domain name at the bottom.


2 Answers

with pythonwhois if you favor, it could be

>>> import pythonwhois  # i'm using this http://cryto.net/pythonwhois >>> domains = ['google.com', 'stackoverflow.com'] >>> for dom in domains: ...     details = pythonwhois.get_whois(dom) ...     print details['contacts']['registrant']  

which returns a dictionary

{'city': u'Mountain View',  'fax': u'+1.6506188571',  'name': u'Dns Admin',  'state': u'CA',  'phone': u'+1.6502530000',  'street': u'Please contact contact- [email protected], 1600 Amphitheatre Parkway',  'country': u'US',  'postalcode': u'94043',  'organization': u'Google Inc.',  'email': u'[email protected]'}  {'city': u'New York',   'name': u'Sysadmin Team',   'state': u'NY',   'phone': u'+1.2122328280',   'street': u'1 Exchange Plaza , Floor 26',   'country': u'US',   'postalcode': u'10006',   'organization': u'Stack Exchange, Inc.',   'email': u'[email protected]'} 

edit: i checked your whois this code worked for me.

>>> import whois >>> domains = ['google.com', 'stackoverflow.com'] >>> for dom in domains: ...     domain = whois.query(dom) ...     print domain.name, domain.registrar ...  google.com MARKMONITOR INC. stackoverflow.com NAME.COM, INC. 

this api uses unix/linux's whois shell command and as it shown here you shouldn't add http:// before domain name. or if you have a unix/linux machine test this:

$ whois google.com  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 ... 

but with http (it is maybe because of http(s) is a just a protocol type, and doesn't have any realiton with domain name itself)

$ whois http://google.com No whois server is known for this kind of object. 
like image 131
marmeladze Avatar answered Oct 12 '22 06:10

marmeladze


I've had issues with python-whois in Python 3, but Python 2 works fine for me using the following code.

First, I would recommend uninstalling any whois module(s) you might have installed. Both python-whois (0.6.1) and whois (0.7) use the same import whois, which created some additional confusion for me.

Next, install python-whois through Command Prompt, Terminal, etc.

pip install python-whois

Once installed, enter the following code in your preferred python IDE.

""" Python = 2.79 OS = Windows 10 IDE = PyCharm 4.5 PyPIPackage = python-whois 0.6.1 """  import whois url = 'example.com' w = whois.whois(url) print w 

The result is a dictionary.

{   "updated_date": "2015-08-14 00:00:00",    "status": [     "clientDeleteProhibited https://icann.org/epp#clientDeleteProhibited",      "clientTransferProhibited https://icann.org/epp#clientTransferProhibited",      "clientUpdateProhibited https://icann.org/epp#clientUpdateProhibited"   ],    "name": null,    "dnssec": null,    "city": null,    "expiration_date": "2016-08-13 00:00:00",  ... ... ...   "address": null,    "name_servers": [     "A.IANA-SERVERS.NET",      "B.IANA-SERVERS.NET"   ],    "org": null,    "creation_date": "1995-08-14 00:00:00",    "emails": null } 
like image 22
datalifenyc Avatar answered Oct 12 '22 06:10

datalifenyc