使用python进行whois查询

发布时间:2019-09-16 07:33:29编辑:auto阅读(2551)

    使用python进行whois查询

    使用pip命令安装whois

    pip install python-whois

    Python 2.7.6 (default, Oct 26 2016, 20:30:19) 
    [GCC 4.8.4] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import whois
    >>>

    安装成功


    使用方法

    [GCC 4.8.4] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import whois

    使用

    whois.whois(URL)

    来查询域名的whois信息

    
    >>> data = whois.whois("www.wangjunx.top")
    >>> data
    {u'updated_date': datetime.datetime(2017, 7, 6, 2, 12, 42), u'status': u'ok https://icann.org/epp#OK', u'name': u'Wang Jun Xiong', u'dnssec': u'unsigned', u'city': u'Hangzhou', u'expiration_date': datetime.datetime(2018, 7, 6, 2, 12, 8), u'zipcode': u'311121', u'domain_name': u'wangjunx.top', u'country': u'CN', u'whois_server': u'http://whois.hichina.com/', u'state': u'Zhejiang', u'registrar': u'Alibaba Cloud Computing Ltd. d/b/a HiChina (www.net.cn)', u'referral_url': None, u'address': u'Le Jia International No.999 Liang Mu Road Yuhang District', u'name_servers': [u'dns7.hichina.com', u'dns8.hichina.com'], u'org': u'Wang Jun Xiong', u'creation_date': datetime.datetime(2017, 7, 6, 2, 12, 8), u'emails': [u'DomainAbuse@service.aliyun.com', u'1411349759@qq.com', u'YuMing@YinSiBaoHu.AliYun.com']}

    得到的whois服务器返回的信息(class)

    >>> type(data)
    <class 'whois.parser.WhoisEntry'>

    得到对应的关键字信息

    >>> data['city']
    u'Hangzhou'

关键字