暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

一文搞定:whois数据库查询域名信息(WHOIS)

Coding Big Tree 2023-04-10
902

目录

  • 1、Whois前置知识
  • 2、通过网页查询
    • 2.1、方式一:通过原始网页查询
    • 2.2、方式二:第三方网站查询
  • 3、命令行whois查询
    • 3.1、Windows环境命令行whois查询
    • 3.2、Linux 环境命令行whois查询
  • 4、Python代码方式实现
    • 4.1、通过Socket实现whois查询
    • 4.2、第三方库:whois
    • 4.3、第三方库:python-whois
    • 4.4、第三方库:whois21
  • 5、使用Domain Admin
  • 参考

1、Whois前置知识

whois就是一个用来查询域名是否已经被注册,以及注册域名的详细信息的数据库
(如域名所有人、域名注册商)。

不同域名后缀的whois信息需要到不同的whois数据库查询

参考:百度百科-whois域名查询协议

实现原理

  1. 根据域名从根服务器获取域名所在whois服务器
  2. 再根据域名从域名所在whois服务器获取域名信息
domain + rootServer => targetServer

domain + targetServer => domainInfo

在这里插入图片描述

当然,如果知道了域名信息所在服务器,可以跳过第一步,直接查询域名信息

2、通过网页查询

2.1、方式一:通过原始网页查询

  1. 第一步:根据域名从根服务器获取域名所在whois服务器

根服务器网站:https://www.iana.org/whois

在这里插入图片描述

或者直接根据域名后缀在数据库中查找对应的whois服务器地址

  • https://www.iana.org/domains/root/db
  1. 第二步:再根据域名从域名所在whois服务器获取域名信息

注意看到返回信息中的refer

refer:        whois.cnnic.cn

打开这个网站: https://whois.cnnic.cn,继续查询, 需要注意,这里查询的是一级域名,不能携带www,只能查询xiaomi.cn

在这里插入图片描述

2.2、方式二:第三方网站查询

域名信息查询网站

  • https://whois.aliyun.com/
  • https://whois.cloud.tencent.com/
  • https://who.is/
  • https://www.whois.com/whois/

这些网站可以直接查询域名信息,他们后台做了优化不用再去逐级查询,可以看到,信息返回的并不是很完整

在这里插入图片描述

3、命令行whois查询

3.1、Windows环境命令行whois查询

官网:

  • https://www.nirsoft.net/utils/whoiscl.html

下载链接:https://www.nirsoft.net/utils/whoiscl.zip

3.2、Linux 环境命令行whois查询

安装

yum install -y whois

查询示例

# 查看使用帮助
$ whois --help

# 查询域名信息
$ whois xiaomi.cn

Domain Name: xiaomi.cn
ROID: 20070518s10001s40338355-cn
Domain Status: clientTransferProhibited
Registrant: 小米科技有限责任公司
Registrant Contact Email: dns-admin@xiaomi.com
Sponsoring Registrar: 厦门易名科技股份有限公司
Name Server: ns3.dnsv5.com
Name Server: ns4.dnsv5.com
Registration Time: 2007-05-18 10:15:59
Expiration Time: 2024-06-18 10:15:59
DNSSEC: unsigned

需要注意,如果是二级域名就查询不到信息

$ whois www.xiaomi.cn
Invalid parameter:www.xiaomi.cn

4、Python代码方式实现

4.1、通过Socket实现whois查询

使用环境

$ python --version
Python 3.7.0


核心代码

# -*- coding: utf-8 -*-

import socket


def whois_request(domain: str, server: str, port=43, timeout=5) -> str:
    """
    发送http请求,获取信息
    :param domain:
    :param server:
    :param port:
    :return:
    """

    # 创建连接
    sock = socket.create_connection((server, port))
    sock.settimeout(timeout)

    # 发送请求
    sock.send(("%s\r\n" % domain).encode("utf-8"))

    # 接收数据
    buff = bytes()
    while True:
        data = sock.recv(1024)
        if len(data) == 0:
            break
        buff += data

    # 关闭链接
    sock.close()

    return buff.decode("utf-8")

1、第一步,根据域名从根服务器获取域名所在whois服务器

# 根服务器地址
root_server = 'whois.iana.org'

# 需要查询的域名
domain = 'xiaoxi.cn'

# 查询域名信息
res = whois_request(domain, root_server)
print(res)

返回数据

% IANA WHOIS server
for more information on IANA, visit http://www.iana.org
% This query returned 1 object

refer:        whois.cnnic.cn

domain:       CN

organisation: China Internet Network Information Center (CNNIC)
address:      No. 4, South 4th Street
address:      Zhong Guan Cun
address:      Beijing 100190
address:      China

contact:      administrative
name:         Yu Zeng
organisation: China Internet Network Information Center (CNNIC)
address:      No. 4, South 4th Street
address:      Zhong Guan Cun
address:      Beijing 100190
address:      China
phone:        +8610-58813686
fax-no:       +8610-58813632
e-mail:       ceo@cnnic.cn

contact:      technical
name:         Yuedong Zhang
organisation: China Internet Network Information Center (CNNIC)
address:      No. 4, South 4th Street
address:      Zhong Guan Cun
address:      Beijing 100190
address:      China
phone:        +8610-58813202
fax-no:       +8610-58812666
e-mail:       tech@cnnic.cn

nserver:      A.DNS.CN 2001:dc7:0:0:0:0:0:1 203.119.25.1
nserver:      B.DNS.CN 203.119.26.1
nserver:      C.DNS.CN 203.119.27.1
nserver:      D.DNS.CN 2001:dc7:1000:0:0:0:0:1 203.119.28.1
nserver:      E.DNS.CN 203.119.29.1
nserver:      F.DNS.CN 195.219.8.90
nserver:      G.DNS.CN 66.198.183.65
nserver:      NS.CERNET.NET 202.112.0.44
ds-rdata:     57724 8 2 5d0423633eb24a499be78aa22d1c0c9ba36218ff49fd95a4cdf1a4ad97c67044

whois:        whois.cnnic.cn

status:       ACTIVE
remarks:      Registration information: http://www.cnnic.cn/

created:      1990-11-28
changed:      2018-03-01
source:       IANA

注意到,这就是该域名信息所在服务器

refer:        whois.cnnic.cn

2、第二步:再根据域名从域名所在whois服务器获取域名信息

# whois服务器地址
whois_server = 'whois.cnnic.cn'

# 需要查询的域名,注意不能带www
domain = 'xiaoxi.cn'

# 查询域名信息
res = whois_request(domain, whois_server)
print(res)

返回的信息

Domain Name: xiaomi.cn
ROID: 20070518s10001s40338355-cn
Domain Status: clientTransferProhibited
Registrant: 小米科技有限责任公司
Registrant Contact Email: dns-admin@xiaomi.com
Sponsoring Registrar: 厦门易名科技股份有限公司
Name Server: ns3.dnsv5.com
Name Server: ns4.dnsv5.com
Registration Time: 2007-05-18 10:15:59
Expiration Time: 2024-06-18 10:15:59
DNSSEC: unsigned

可以看到,我们查询到了和网站查询一样的信息

可以直接使用第三方整理的whois数据库对应地址

  • https://www.nirsoft.net/whois-servers.txt

4.2、第三方库:whois

操作系统命令行工具 whois
的Python封装,依赖操作系统,不推荐

  • https://github.com/DannyCork/python-whois/
  • https://pypi.org/project/whois/

安装

$ pip install whois

示例

import whois

domain = whois.query('www.baidu.com')
print(domain.__dict__)

输出

{
 'name''baidu.com',
 'tld''com',
 'registrar''MarkMonitor Inc.',
 'registrant_country''CN',
 'creation_date': datetime.datetime(1999101111517),
 'expiration_date': datetime.datetime(2026101111517),
 'last_updated': datetime.datetime(20229135443),
 'status''clientDeleteProhibited https://icann.org/epp#clientDeleteProhibited',
 'statuses': ['clientDeleteProhibited (https://www.icann.org/epp#clientDeleteProhibited)''clientDeleteProhibited https://icann.org/epp#clientDeleteProhibited''clientTransferProhibited (https://www.icann.org/epp#clientTransferProhibited)''clientTransferProhibited https://icann.org/epp#clientTransferProhibited''clientUpdateProhibited (https://www.icann.org/epp#clientUpdateProhibited)''clientUpdateProhibited https://icann.org/epp#clientUpdateProhibited''serverDeleteProhibited (https://www.icann.org/epp#serverDeleteProhibited)''serverDeleteProhibited https://icann.org/epp#serverDeleteProhibited''serverTransferProhibited (https://www.icann.org/epp#serverTransferProhibited)''serverTransferProhibited https://icann.org/epp#serverTransferProhibited''serverUpdateProhibited (https://www.icann.org/epp#serverUpdateProhibited)''serverUpdateProhibited https://icann.org/epp#serverUpdateProhibited'],
 'dnssec': False,
 'name_servers': ['ns1.baidu.com''ns2.baidu.com''ns3.baidu.com''ns4.baidu.com''ns7.baidu.com'],
 'registrant''Beijing Baidu Netcom Science Technology Co., Ltd.',
 'emails': ['abusecomplaints@markmonitor.com']
}

json序列化之后得到域名信息

{
    "name":"baidu.com",
    "tld":"com",
    "registrar":"MarkMonitor Inc.",
    "registrant_country":"CN",
    "creation_date":"1999-10-11 11:05:17",
    "expiration_date":"2026-10-11 11:05:17",
    "last_updated":"2022-09-01 03:54:43",
    "status":"clientDeleteProhibited https://icann.org/epp#clientDeleteProhibited",
    "statuses":[
        "clientDeleteProhibited (https://www.icann.org/epp#clientDeleteProhibited)",
        "clientDeleteProhibited https://icann.org/epp#clientDeleteProhibited",
        "clientTransferProhibited (https://www.icann.org/epp#clientTransferProhibited)",
        "clientTransferProhibited https://icann.org/epp#clientTransferProhibited",
        "clientUpdateProhibited (https://www.icann.org/epp#clientUpdateProhibited)",
        "clientUpdateProhibited https://icann.org/epp#clientUpdateProhibited",
        "serverDeleteProhibited (https://www.icann.org/epp#serverDeleteProhibited)",
        "serverDeleteProhibited https://icann.org/epp#serverDeleteProhibited",
        "serverTransferProhibited (https://www.icann.org/epp#serverTransferProhibited)",
        "serverTransferProhibited https://icann.org/epp#serverTransferProhibited",
        "serverUpdateProhibited (https://www.icann.org/epp#serverUpdateProhibited)",
        "serverUpdateProhibited https://icann.org/epp#serverUpdateProhibited"
    ],
    "dnssec":false,
    "name_servers":[
        "ns1.baidu.com",
        "ns2.baidu.com",
        "ns3.baidu.com",
        "ns4.baidu.com",
        "ns7.baidu.com"
    ],
    "registrant":"Beijing Baidu Netcom Science Technology Co., Ltd.",
    "emails":[
        "abusecomplaints@markmonitor.com"
    ]
}

4.3、第三方库:python-whois

经测试,不可用

  • https://github.com/richardpenman/whois
  • https://pypi.org/project/python-whois/
$ pip install python-whois

示例

import whois

w = whois.whois('example.com')

w.expiration_date
# datetime.datetime(2022, 8, 13, 4, 0)

4.4、第三方库:whois21

经测试,可用

  • https://github.com/MPCodeWriter21/whois21
  • https://pypi.org/project/whois21/
pip install whois21

示例

import whois21

query = 'github.com'

whois = whois21.WHOIS(query)

print(f'Creation date   : {whois.creation_date}')
print(f'Expiration date : {whois.expires_date}')
print(f'Updated date    : {whois.updated_date}')

5、使用Domain Admin

基于Python + Vue3.js 技术栈实现的域名和SSL证书监测平台

文档

  • https://gitee.com/mouday/domain-admin
  • https://github.com/mouday/domain-admin
  • https://pypi.org/project/domain-admin
  • https://hub.docker.com/r/mouday/domain-admin

安装

pip install domain-admin

启动运行

$ gunicorn 'domain_admin.main:app'

访问地址:http://127.0.0.1:8000

默认的管理员账号

  • 账号:admin
  • 密码:123456
在这里插入图片描述

参考

  • Windows和Linux下Whois命令的安装和使用


域名服务器 数据库服务器 域名后缀 whois 域名
文章转载自 Coding Big Tree,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论

玻璃钢生产厂家南阳不锈钢太湖石玻璃钢雕塑邯郸附近玻璃钢彩绘雕塑玻璃钢商场美陈座椅广州玻璃钢彩绘雕塑价格玻璃钢维尼熊系列雕塑东营玻璃钢雕塑生产商玻璃钢大米卡通雕塑江苏玻璃钢花盆哪家好东莞景观玻璃钢人物雕塑肇庆玻璃钢动物雕塑现货河南室内商场美陈生产企业景观雕塑厂家玻璃钢铜陵水果玻璃钢雕塑定做价格定做形象卡通游乐园玻璃钢雕塑浙江室外玻璃钢花盆日照校园玻璃钢雕塑阜阳玻璃钢雕塑优势昆明市玻璃钢雕塑哪里买梅花鹿雕塑摆件玻璃钢嘉兴玻璃钢雕塑订做价格仿真人物玻璃钢雕塑定制兰州玻璃钢雕塑制作的公司绍兴园林玻璃钢雕塑定制江苏镜面玻璃钢雕塑性价比高三亚专业玻璃钢花盆厂家价格华龙玻璃钢雕塑厂家张掖玻璃钢十二生肖雕塑铜陵户外玻璃钢雕塑定做价格商场热带丛林主题美陈商场春节小店美陈香港通过《维护国家安全条例》两大学生合买彩票中奖一人不认账让美丽中国“从细节出发”19岁小伙救下5人后溺亡 多方发声单亲妈妈陷入热恋 14岁儿子报警汪小菲曝离婚始末遭遇山火的松茸之乡雅江山火三名扑火人员牺牲系谣言何赛飞追着代拍打萧美琴窜访捷克 外交部回应卫健委通报少年有偿捐血浆16次猝死手机成瘾是影响睡眠质量重要因素高校汽车撞人致3死16伤 司机系学生315晚会后胖东来又人满为患了小米汽车超级工厂正式揭幕中国拥有亿元资产的家庭达13.3万户周杰伦一审败诉网易男孩8年未见母亲被告知被遗忘许家印被限制高消费饲养员用铁锨驱打大熊猫被辞退男子被猫抓伤后确诊“猫抓病”特朗普无法缴纳4.54亿美元罚金倪萍分享减重40斤方法联合利华开始重组张家界的山上“长”满了韩国人?张立群任西安交通大学校长杨倩无缘巴黎奥运“重生之我在北大当嫡校长”黑马情侣提车了专访95后高颜值猪保姆考生莫言也上北大硕士复试名单了网友洛杉矶偶遇贾玲专家建议不必谈骨泥色变沉迷短剧的人就像掉进了杀猪盘奥巴马现身唐宁街 黑色着装引猜测七年后宇文玥被薅头发捞上岸事业单位女子向同事水杯投不明物质凯特王妃现身!外出购物视频曝光河南驻马店通报西平中学跳楼事件王树国卸任西安交大校长 师生送别恒大被罚41.75亿到底怎么缴男子被流浪猫绊倒 投喂者赔24万房客欠租失踪 房东直发愁西双版纳热带植物园回应蜉蝣大爆发钱人豪晒法院裁定实锤抄袭外国人感慨凌晨的中国很安全胖东来员工每周单休无小长假白宫:哈马斯三号人物被杀测试车高速逃费 小米:已补缴老人退休金被冒领16年 金额超20万

玻璃钢生产厂家 XML地图 TXT地图 虚拟主机 SEO 网站制作 网站优化