检查域是否已注册 [英] Check whether domain is registered
问题描述
我正在尝试制作一个返回未注册域的脚本.我正在使用 Python 2.7.我读到模块 whois
应该能够做到这一点,但我编写的代码引发了错误.
代码:
导入whois域 = ['http://www.example.com']对于域中的 dom:域 = whois.Domain(dom)打印域.registrar
错误:
domain = whois.Domain(dom)文件C:Python27libsite-packageswhois\_3_adjust.py",第 12 行,在 __init__self.name = data['domain_name'][0].strip().lower()类型错误:字符串索引必须是整数,而不是 str
你知道哪里出了问题吗?或者你能给我一个更好的解决方案吗?
我尝试了 pythonwhois 模块,但它也返回一个错误.
根据此处的一个解决方案,在 SO 上,我尝试使用 pywhois
,此代码也会引发错误.
导入pywhoisw = pywhois.whois('google.com')w.expiration_date
错误:
w = pywhois.whois('google.com')AttributeError: 'module' 对象没有属性 'whois'
如果你愿意,可以使用 pythonwhois
<预><代码>>>>导入 pythonwhois # 我正在使用这个 http://cryto.net/pythonwhois>>>域 = ['google.com', 'stackoverflow.com']>>>对于域中的 dom:... 详细信息 = pythonwhois.get_whois(dom)...打印详细信息['联系人']['注册人']返回字典
{'city': u'Mountain View','传真':u'+1.6506188571','name': u'Dns Admin','状态':你'CA','电话':你'+1.6502530000','street':你'请联系 admin@google.com,1600 Amphitheatre Parkway','国家':你'美国','邮政编码':u'94043','组织':u'Google Inc.','电子邮件':u'dns-admin@google.com'}{'城市':你'纽约','name': u'系统管理员团队','state': u'NY','电话':你'+1.2122328280','street': u'1 Exchange Plaza , Floor 26','国家':你'美国','邮政编码': u'10006','组织':u'Stack Exchange, Inc.','电子邮件':u'sysadmin-team@stackoverflow.com'}
我检查了你的whois
这段代码对我有用.
此 api 使用 unix/linux 的 whois shell 命令,如此处您不应该在域名前添加 http://
.或者如果你有一台 unix/linux 机器测试这个:
$ whois google.comWhois 服务器版本 2.0现在可以注册 .com 和 .net 域中的域名与许多不同的竞争注册商.转至 http://www.internic.net详细信息...
但是使用http(可能是因为http(s)只是一种协议类型,与域名本身没有任何关系)
$ whois http://google.com对于这种对象,没有已知的 whois 服务器.
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:Python27libsite-packageswhois\_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'
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- admin@google.com, 1600 Amphitheatre Parkway',
'country': u'US',
'postalcode': u'94043',
'organization': u'Google Inc.',
'email': u'dns-admin@google.com'}
{'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'sysadmin-team@stackoverflow.com'}
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.
这篇关于检查域是否已注册的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!