1.IP查詢python
IP查詢是經過當前所獲取到的URL去查詢對應IP地址的過程.能夠應用socket庫函數中的gethostbuname()獲取域名所對應的IP值,代碼以下:數據庫
查詢域名www.biadu.com所對應的IP值,代碼以下:dom
>>> import socket >>> ip = socket.gethostbyname('www.biadu.com') >>> print(ip)
輸出結果:socket
112.80.248.75
2.whois查詢函數
whois是用來查詢域名的ip以及全部者信息的傳輸協議.簡單地說,whois就是一個數據庫,用來查詢域名是否已經別註冊,以及註冊域名的詳細信息(如域名全部人,域名註冊商等).Python中的模塊Python-whois 可用於whois的查詢url
首先經過pip安裝Python-whois:spa
pip install python-whoiscode
經過Python自帶的whois模塊查詢域名www.baidu.com的註冊信息,代碼以下:server
>>> from whois inport whois >>> data =whois('www.baidu.com') >>> pirnt(data)
輸入結果:blog
{ "domain_name": [ "BAIDU.COM", "baidu.com" ], "registrar": "MarkMonitor, Inc.", "whois_server": "whois.markmonitor.com", "referral_url": null, "updated_date": [ "2020-12-09 04:04:41", "2020-12-08 19:39:35-08:00" ], "creation_date": [ "1999-10-11 11:05:17", "1999-10-11 04:05:17-07:00" ], "expiration_date": [ "2026-10-11 11:05:17", "2026-10-11 00:00:00-07:00" ], "name_servers": [ "NS1.BAIDU.COM", "NS2.BAIDU.COM", "NS3.BAIDU.COM", "NS4.BAIDU.COM", "NS7.BAIDU.COM", "ns1.baidu.com", "ns2.baidu.com", "ns3.baidu.com", "ns7.baidu.com", "ns4.baidu.com" ], "status": [ "clientDeleteProhibited https://icann.org/epp#clientDeleteProhibited", "clientTransferProhibited https://icann.org/epp#clientTransferProhibited", "clientUpdateProhibited https://icann.org/epp#clientUpdateProhibited", "serverDeleteProhibited https://icann.org/epp#serverDeleteProhibited", "serverTransferProhibited https://icann.org/epp#serverTransferProhibited", "serverUpdateProhibited https://icann.org/epp#serverUpdateProhibited", "clientUpdateProhibited (https://www.icann.org/epp#clientUpdateProhibited)", "clientTransferProhibited (https://www.icann.org/epp#clientTransferProhibited)", "clientDeleteProhibited (https://www.icann.org/epp#clientDeleteProhibited)" ], "emails": [ "abusecomplaints@markmonitor.com", "whoisrequest@markmonitor.com" ], "dnssec": "unsigned", "name": null, "org": "Beijing Baidu Netcom Science Technology Co., Ltd.", "address": null, "city": null, "state": "Beijing", "zipcode": null, "country": "CN" } Process finished with exit code 0