5 import socket |
5 import socket |
6 from parser import WhoisEntry |
6 from parser import WhoisEntry |
7 from whois import NICClient |
7 from whois import NICClient |
8 |
8 |
9 |
9 |
10 def whois(url): |
10 def whois(url, experimental=False): |
11 # clean domain to expose netloc |
11 # clean domain to expose netloc |
12 ip_match = re.match(r"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$", url) |
12 ip_match = re.match(r"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$", url) |
13 if ip_match: |
13 if ip_match: |
14 domain = url |
14 domain = url |
15 else: |
15 else: |
16 domain = extract_domain(url) |
16 domain = extract_domain(url) |
17 try: |
17 if not experimental: |
18 # try native whois command first |
18 try: |
19 r = subprocess.Popen(['whois', domain], stdout=subprocess.PIPE) |
19 # try native whois command first |
20 text = r.stdout.read() |
20 r = subprocess.Popen(['whois', domain], stdout=subprocess.PIPE) |
21 except OSError: |
21 text = r.stdout.read() |
22 # try experimental client |
22 except OSError: |
|
23 # try experimental client |
|
24 nic_client = NICClient() |
|
25 text = nic_client.whois_lookup(None, domain, 0) |
|
26 else: |
23 nic_client = NICClient() |
27 nic_client = NICClient() |
24 text = nic_client.whois_lookup(None, domain, 0) |
28 text = nic_client.whois_lookup(None, domain, 0) |
25 return WhoisEntry.load(domain, text) |
29 return WhoisEntry.load(domain, text) |
26 |
30 |
27 |
31 |