Skip to content

Commit

Permalink
Merge pull request #1 from richardpenman/master
Browse files Browse the repository at this point in the history
Pull from origin
  • Loading branch information
pipozzz committed Jan 14, 2020
2 parents a10e26b + c6b441a commit a4794c4
Show file tree
Hide file tree
Showing 11 changed files with 230 additions and 68 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sys, os
import setuptools

version = '0.7.0'
version = '0.7.2'

setuptools.setup(
name='python-whois',
Expand Down
2 changes: 1 addition & 1 deletion test/samples/expected/google.de
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"domain_name": "google.de", "status": "connect", "updated_date": "2018-03-12T21:44:25+01:00", "name": null, "org": null, "address": null, "zipcode": null, "city": null, "country_code": null, "phone": null, "fax": null, "name_servers": ["ns1.google.com", "ns2.google.com", "ns3.google.com", "ns4.google.com"], "emails": null}
{"domain_name": "google.de", "status": "connect", "updated_date": "2018-03-12 21:44:25+01:00", "name": null, "org": null, "address": null, "zipcode": null, "city": null, "country_code": null, "phone": null, "fax": null, "name_servers": ["ns1.google.com", "ns2.google.com", "ns3.google.com", "ns4.google.com"], "emails": null}
2 changes: 1 addition & 1 deletion test/samples/expected/sapo.pt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"domain_name": "sapo.pt", "expiration_date": "2018-11-02 00:00:00", "updated_date": null, "creation_date": "2002-10-30 00:00:00", "status": "ACTIVE"}
{"domain_name": "sapo.pt", "expiration_date": "2019-11-02 23:59:00", "updated_date": null, "creation_date": "2002-10-30 00:00:00", "status": "Registered"}
2 changes: 1 addition & 1 deletion test/samples/expected/web.de
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"domain_name": "web.de", "expiration_date": null, "updated_date": ["2016-04-11T11:09:54+02:00", "2011-08-10T17:09:10+02:00"], "creation_date": null, "status": "connect"}
{"domain_name": "web.de", "expiration_date": null, "updated_date": ["2016-04-11 11:09:54+02:00", "2011-08-10 17:09:10+02:00"], "creation_date": null, "status": "connect"}
51 changes: 20 additions & 31 deletions test/samples/whois/sapo.pt
Original file line number Diff line number Diff line change
@@ -1,31 +1,20 @@
Nome de domínio / Domain Name: sapo.pt
Data de registo / Creation Date (dd/mm/yyyy): 30/10/2002
Data de expiração / Expiration Date (dd/mm/yyyy): 02/11/2018
Estado / Status: ACTIVE

Titular / Registrant
MEO - SERVIÇOS DE COMUNICAÇÕES E MULTIMÉDIA S.A.
A/C Direção de Tecnologias de Informação
Av. Fontes Pereira de Melo, 40
1069-300 Lisboa
Email: gestao.dominios@telecom.pt

Entidade Gestora / Billing Contact
MEO - SERVIÇOS DE COMUNICAÇÕES E MULTIMÉDIA S.A.
Email: gestao.dominios@telecom.pt

Responsável Técnico / Tech Contact
MEO - SERVIÇOS DE COMUNICAÇÕES E MULTIMÉDIA S.A.
Email: gestao.dominios@telecom.pt

Nameserver Information
Nameserver: sapo.pt NS ns2.sapo.pt.
Nameserver: sapo.pt NS dns02.sapo.pt.
Nameserver: sapo.pt NS ns.sapo.pt.
Nameserver: sapo.pt NS dns01.sapo.pt.
Nameserver: ns2.sapo.pt. A 212.55.154.194
Nameserver: dns02.sapo.pt. AAAA 2001:8a0:2206:4:213:13:30:116
Nameserver: ns.sapo.pt. A 212.55.154.202
Nameserver: dns01.sapo.pt. AAAA 2001:8a0:2106:4:213:13:28:116
Nameserver: dns01.sapo.pt. A 213.13.28.116
Nameserver: dns02.sapo.pt. A 213.13.30.116
Domain: sapo.pt
Domain Status: Registered
Creation Date: 30/10/2002 00:00:00
Expiration Date: 02/11/2019 23:59:00
Owner Name: MEO - SERVI?OS DE COMUNICA??ES E MULTIM?DIA S.A.
Owner Address: A/C Dire??o de Tecnologias de Informa??o
Owner Locality: Av. Fontes Pereira de Melo, 40
Owner ZipCode: 1069-300
Owner Locality ZipCode: Av. Fontes Pereira de Melo, 40
Owner Email: gestao.dominios@telecom.pt
Admin Name: MEO - SERVI?OS DE COMUNICA??ES E MULTIM?DIA S.A.
Admin Address: A/C Dire??o de Tecnologias de Informa??o
Admin Locality: Av. Fontes Pereira de Melo, 40
Admin ZipCode: 1069-300
Admin Locality ZipCode: Av. Fontes Pereira de Melo, 40
Admin Email: gestao.dominios@telecom.pt
Name Server: ns2.sapo.pt | IPv4: 212.55.154.194 and IPv6:
Name Server: dns01.sapo.pt | IPv4: 213.13.28.116 and IPv6: 2001:8a0:2106:4:213:13:28:116
Name Server: dns02.sapo.pt | IPv4: 213.13.30.116 and IPv6: 2001:8a0:2206:4:213:13:30:116
Name Server: ns.sapo.pt | IPv4: 212.55.154.202 and IPv6:
14 changes: 14 additions & 0 deletions test/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,17 @@ def test_unicode_domain_and_tld(self):
url = 'http://россия.рф/'
domain = 'россия.рф'
self.assertEqual(domain, extract_domain(url))

def test_ipv6(self):
""" Verify that ipv6 addresses work """
url = '2607:f8b0:4006:802::200e'
domain = '1e100.net'
# double extract_domain() so we avoid possibly changing hostnames like lga34s12-in-x0e.1e100.net
self.assertEqual(domain, extract_domain(extract_domain(url)))

def test_ipv4(self):
""" Verify that ipv4 addresses work """
url = '172.217.3.110'
domain = '1e100.net'
# double extract_domain() so we avoid possibly changing hostnames like lga34s18-in-f14.1e100.net
self.assertEqual(domain, extract_domain(extract_domain(url)))
38 changes: 36 additions & 2 deletions test/test_parser.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import print_function
from __future__ import unicode_literals
from __future__ import division
Expand Down Expand Up @@ -97,7 +98,7 @@ def date2str4json(obj):
print("%s \t(%s):\t Missing in results" % (domain, key,))
fail += 1
continue

result = results.get(key)
if isinstance(result, list):
result = [str(element) for element in result]
Expand Down Expand Up @@ -125,7 +126,7 @@ def test_ca_parse(self):
Registry Registrant ID: 70
Registrant Name: Test Industries
Registrant Organization:
Registrant Organization:
Admin Name: Test Person1
Admin Street: Test Address
Expand Down Expand Up @@ -169,6 +170,39 @@ def test_ca_parse(self):
}
self._parse_and_compare('testcompany.ca', data, expected_results,
whois_entry=WhoisCa)

def test_cn_parse(self):
data = """
Domain Name: cnnic.com.cn
ROID: 20021209s10011s00047242-cn
Domain Status: serverDeleteProhibited
Domain Status: serverUpdateProhibited
Domain Status: serverTransferProhibited
Registrant ID: s1255673574881
Registrant: 中国互联网络信息中心
Registrant Contact Email: servicei@cnnic.cn
Sponsoring Registrar: 北京新网数码信息技术有限公司
Name Server: a.cnnic.cn
Name Server: b.cnnic.cn
Name Server: c.cnnic.cn
Name Server: d.cnnic.cn
Name Server: e.cnnic.cn
Registration Time: 2000-09-14 00:00:00
Expiration Time: 2023-08-16 16:26:39
DNSSEC: unsigned
"""
expected_results = {
"domain_name": "cnnic.com.cn",
"registrar": "北京新网数码信息技术有限公司",
"creation_date": "2000-09-14 00:00:00",
"expiration_date": "2023-08-16 16:26:39",
"name_servers": ["a.cnnic.cn", "b.cnnic.cn", "c.cnnic.cn", "d.cnnic.cn", "e.cnnic.cn"],
"status": ["serverDeleteProhibited", "serverUpdateProhibited", "serverTransferProhibited"],
"emails": "servicei@cnnic.cn",
"dnssec": "unsigned",
"name": "中国互联网络信息中心"
}
self._parse_and_compare('cnnic.com.cn', data, expected_results)

def test_il_parse(self):
data = """
Expand Down
24 changes: 24 additions & 0 deletions test/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,27 @@ def test_simple_unicode_domain(self):
def test_unicode_domain_and_tld(self):
domain = 'россия.рф'
whois(domain)

def test_ipv4(self):
""" Verify ipv4 addresses. """
domain = '172.217.3.110'
whois_results = whois(domain)
if isinstance(whois_results['domain_name'], list):
domain_names = [_.lower() for _ in whois_results['domain_name']]
else:
domain_names = [whois_results['domain_name'].lower()]

self.assertIn('1e100.net', domain_names)
self.assertIn('ns1.google.com', [_.lower() for _ in whois_results['name_servers']])

def test_ipv6(self):
""" Verify ipv6 addresses. """
domain = '2607:f8b0:4006:802::200e'
whois_results = whois(domain)
if isinstance(whois_results['domain_name'], list):
domain_names = [_.lower() for _ in whois_results['domain_name']]
else:
domain_names = [whois_results['domain_name'].lower()]

self.assertIn('1e100.net', domain_names)
self.assertIn('ns1.google.com', [_.lower() for _ in whois_results['name_servers']])
11 changes: 9 additions & 2 deletions whois/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@
from .whois import NICClient


# thanks to https://www.regextester.com/104038
IPV4_OR_V6 = re.compile(r"((^\s*((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))\s*$)|(^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$))")


def whois(url, command=False, flags=0):
# clean domain to expose netloc
ip_match = re.match(r"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$", url)
ip_match = IPV4_OR_V6.match(url)
if ip_match:
domain = url
try:
Expand Down Expand Up @@ -63,8 +66,12 @@ def extract_domain(url):
globo.com
>>> print(extract_domain('1-0-1-1-1-0-1-1-1-1-1-1-1-.0-0-0-0-0-0-0-0-0-0-0-0-0-10-0-0-0-0-0-0-0-0-0-0-0-0-0.info'))
0-0-0-0-0-0-0-0-0-0-0-0-0-10-0-0-0-0-0-0-0-0-0-0-0-0-0.info
>>> print(extract_domain('2607:f8b0:4006:802::200e'))
1e100.net
>>> print(extract_domain('172.217.3.110'))
1e100.net
"""
if re.match(r'\d+\.\d+\.\d+\.\d+', url):
if IPV4_OR_V6.match(url):
# this is an IP address
return socket.gethostbyaddr(url)[0]

Expand Down
Loading

0 comments on commit a4794c4

Please sign in to comment.