当前位置: 首页 > python > 正文

python 实现whois功能

Linux下使用whois domain.name 即可获得该域名的注册信息,其实python也可以实现这个操作。

原理:调用python的socket模块,连接whois server,交互式输入需要查询的域名,获得返回的结果即可。

如同使用telnet:

$telnet whois.internic.net 43
Trying 199.7.51.74…
Connected to whois.internic.net.
Escape character is ‘^]’.
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.

GOOGLE.COM.ZZZZZ.GET.LAID.AT.WWW.SWINGINGCOMMUNITY.COM
GOOGLE.COM.ZZZZZ.DOWNLOAD.MOVIE.ONLINE.ZML2.COM
GOOGLE.COM.ZOMBIED.AND.HACKED.BY.WWW.WEB-HACK.COM
… …
——————————–

下面是python代码

#!/usr/bin/python
#whois.py
import sys
import socket

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

#for com,net后缀的域名
s.connect((“whois.internic.net”, 43))
#for .org 后缀的域名
#s.connect((“whois.publicinterestregistry.net”, 43))
#for .cn 后缀的域名
#s.connect((“whois.cnnic.net.cn”, 43))
”’另外其他后缀的whois server暂时还没有找到,下面的一些whois server,应该是有ip访问许可,并不对普通用户开放。
”’
#s.connect((“whois.networksolutions.com”, 43))
#s.connect((“whois.onlinenic.com”, 43))
#s.connect((“grs.hichina.com”,43))

s.send(sys.argv[1] + “\r\n”)
response = ”
while True:
    data = s.recv(4096)
    response += data
    if data == ”:
        break
s.close()
print response

本文固定链接: https://www.2hei.net/2009/04/04/python_whois/ | 2hei.net

该日志由 u2 于2009年04月04日发表在 python 分类下,
原创文章转载请注明: python 实现whois功能 | 2hei.net
关键字:

python 实现whois功能:目前有1 条留言