怎样使用mwhois

2018年7月1日 由 Amon

官网:https://github.com/jrosco/mwhois

【介绍】

m-whois是一个用Python开发的WHOIS查询模块。可以通过提供一个文件或者列表来找出尚未注册的域名。

要求:Python >= 2.7.3;暂不支持 Python 3。

代理:如果需要启用代理特性,需要安装 pysocks 模块。
下载:https://pypi.python.org/pypi/PySocks/

特性:
1. 直接连接WHOIS服务器查询单个/多个域名。
2. 仅输出尚未注册的域名。
3. 支持100多个后缀和30多个新后缀。
4. 支持如果首要WHOIS服务器被墙,可以备用WHOIS服务器(某些后缀的域名管理局是这样限制的)。
5. 通过代理连接WHOIS服务器。

计划特性:
1. 缓存查询结果以实现更快地响应,同时避免滥用域名管理局是的查询限制。
2. 输出查询结果为.CSV和.PDF文件。

【安装】

git clone https://github.com/jrosco/mwhois.git mwhois && cd mwhois && python setup.py install

输出:

...
creating /usr/local/lib/python2.7/site-packages/mwhois
copying build/lib/mwhois/util.py -> /usr/local/lib/python2.7/site-packages/mwhois
...
byte-compiling /usr/local/lib/python2.7/site-packages/mwhois/util.py to util.pyc
...
running install_egg_info
Writing /usr/local/lib/python2.7/site-packages/mwhois-0.1.1b-py2.7.egg-info

【使用】

查询单个域名:

python examples/cmd.py github.com

输出:

   Domain Name: GITHUB.COM
   Registry Domain ID: 1264983250_DOMAIN_COM-VRSN
   Registrar WHOIS Server: whois.markmonitor.com
   Registrar URL: http://www.markmonitor.com
   Updated Date: 2017-06-26T16:02:39Z
   Creation Date: 2007-10-09T18:20:50Z
   Registry Expiry Date: 2020-10-09T18:20:50Z
   Registrar: MarkMonitor Inc.
...

查询多个域名:

数据:-t 后面的参数表示域名后缀;wordlist-sample中分行存储有多个关键词。

python examples/cmd.py -t com -i files/wordlist-sample

输出:

uucp.com                      Domain Taken
nuucp.com                     Domain Available
device.com                    Domain Taken
sysdiags.com                  Domain Available
...

图形界面:

使用默认的 TkInter 模块:

python examples/GUI/mgui.py

参考:https://sourceforge.net/projects/xwh0i5/
源码:https://sourceforge.net/projects/xwh0i5/files/source/

【代码】

获得指定域名的WHOIS服务器:

from mwhois.whois import WhoisInfo
w = WhoisInfo()
w.domain = "on.net"
whoisserver = w.get_whois_server()
print(whoisserver)

输出:

whois.internic.net

从WHOIS服务器返回指定域名用于指示’not found’的字符串:

from mwhois.whois import WhoisInfo
w2 = WhoisInfo()
w2.domain = "ping.net"
w2.get_domain_tld()
txt = w2.tld_not_found_text()
print(txt)

输出:

No match for

从WHOIS服务器返回指定域名后缀用于指示’not found’的字符串:

from mwhois.whois import WhoisInfo
w3 = WhoisInfo()
w3.tld = "jp"
txt2 = w3.tld_not_found_text()
print(txt2)

输出:

No match!!

单域名查询,输出原始WHOIS数据(设置 s.connection.proxy = true 以设置代理):

from mwhois.whosearch import WhoisSearch
import mwhois.const as CONST
s = WhoisSearch(dname='sohu.com', debug=False)
s.connection.proxy = False
s.connection.proxy_host = '127.0.0.1'
s.connection.proxy_port = 8080
s.connection.proxy_type = CONST.PROXY_TYPE_SOCKS5
s.whois_search()
print(s.response())

输出:

Domain Name: cnnic.cn
ROID: 20030310s10001s00012956-cn
Domain Status: serverDeleteProhibited
Domain Status: serverUpdateProhibited
Domain Status: serverTransferProhibited
Registrant ID: s1255673574881
Registrant: 中国互联网络信息中心
Registrant Contact Email: servicei@cnnic.cn
...

单域名查询,输出WHOIS数据的元数据(设置 s.connection.proxy = true 以设置代理):

from mwhois.whosearch import WhoisSearch
import mwhois.const as CONST
s = WhoisSearch(dname='sohu.com', debug=False)
s.connection.proxy = False
s.connection.proxy_host = '127.0.0.1'
s.connection.proxy_port = 8080
s.connection.proxy_type = CONST.PROXY_TYPE_SOCKS5
s.whois_search()
print(s.creation_date())
print(s.expiry_date())
print(s.update_date())
print(s.registrant())
print(s.nameservers())
print(s.emails())

输出:

1998-7-5
N/A
2017-10-30
[]
[' NS11.SOHU.COM\r', ' NS12.SOHU.COM\r', ' NS13.SOHU.COM\r', ' NS14.SOHU.COM\r', ' NS15.SOHU.COM\r', ' NS16.SOHU.COM\r']
[]

多域名查询(设置 deadonly=False 以显示所有域名状态):

from mwhois.whosearch import WhoisSearch
domain_list = ['google','doesnotexist123','yahoo']
m = WhoisSearch(tld='org',wordlist=domain_list, deadonly=False)
multi = m.whois_multi_search()
"""Returns True(1) if found or False(0) is not found"""
for i in multi:
    print i

输出:

[1, 'google.org']
[0, 'doesnotexist123.org']
[1, 'yahoo.org']

通过文件导入进行多域名查询,输出域名状态:

from mwhois.whosearch import WhoisSearch
m = WhoisSearch(debug=False)
m.tld='com'
m.wordlist='./wordlist.txt'
txt_file = m.whois_multi_search()
""" Loop over txt_file generator and print list results containing ['status value', 'domain name']""" 
for x in txt_file:
    domain = x[1]
    if x[0] == 1:
        status = 'taken'
    else:
        status = 'not taken'
    print('Domain %s is %s ' % (domain, status))

输出:

Domain google.com is taken
...
Domain rewrvdfgrefdvf.com is not taken
Domain fgfdbfdvfdvffv.com is not taken
Domain devadmin.com is taken

通过文件导入进行多域名查询,输出域名属性:

from mwhois.whosearch import WhoisSearch
m = WhoisSearch(debug=False)
m.tld='com'
m.wordlist='./wordlist.txt'
txt_file = m.whois_multi_search()
""" Loop over txt_file generator and print whois attributes"""
for x in txt_file:
    domain = x[1]
    try: 
        date = m.creation_date()[0]
    except:
        date = 'N/A'
    print('Domain %s has creation date %s' % (domain, date))

输出:

Domain phield.com has creation date 2
Domain sohu.com has creation date 1
Domain ebookle.com has creation date 2
广告位
Sedo.com

评论已关闭.