| author | Richard Penman |
| Wed, 16 Mar 2016 15:08:15 +0100 | |
| changeset 80 | fa9650e9ec23 |
| parent 65 | 50b5966b5566 |
| child 81 | 359baebcf0e8 |
| permissions | -rw-r--r-- |
| 0 | 1 |
""" |
2 |
Whois client for python |
|
3 |
||
4 |
transliteration of: |
|
5 |
http://www.opensource.apple.com/source/adv_cmds/adv_cmds-138.1/whois/whois.c |
|
6 |
||
7 |
Copyright (c) 2010 Chris Wolf |
|
8 |
||
9 |
Permission is hereby granted, free of charge, to any person obtaining a copy |
|
10 |
of this software and associated documentation files (the "Software"), to deal |
|
11 |
in the Software without restriction, including without limitation the rights |
|
12 |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
13 |
copies of the Software, and to permit persons to whom the Software is |
|
14 |
furnished to do so, subject to the following conditions: |
|
15 |
||
16 |
The above copyright notice and this permission notice shall be included in |
|
17 |
all copies or substantial portions of the Software. |
|
18 |
||
19 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
20 |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
21 |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
22 |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
23 |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
24 |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|
25 |
THE SOFTWARE. |
|
26 |
""" |
|
|
62
fc06c601b875
whois client was using the first whois server in list rather than the whois server associated with the domain we are querying issue #74
Richard Penman
parents:
60
diff
changeset
|
27 |
import re |
| 0 | 28 |
import sys |
29 |
import socket |
|
30 |
import optparse |
|
|
32
5f851e9c196a
Stylistic fixes on the NICClient class
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
12
diff
changeset
|
31 |
|
| 0 | 32 |
|
|
32
5f851e9c196a
Stylistic fixes on the NICClient class
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
12
diff
changeset
|
33 |
|
|
5f851e9c196a
Stylistic fixes on the NICClient class
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
12
diff
changeset
|
34 |
class NICClient(object): |
| 0 | 35 |
|
|
32
5f851e9c196a
Stylistic fixes on the NICClient class
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
12
diff
changeset
|
36 |
ABUSEHOST = "whois.abuse.net" |
|
5f851e9c196a
Stylistic fixes on the NICClient class
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
12
diff
changeset
|
37 |
NICHOST = "whois.crsnic.net" |
|
5f851e9c196a
Stylistic fixes on the NICClient class
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
12
diff
changeset
|
38 |
INICHOST = "whois.networksolutions.com" |
|
5f851e9c196a
Stylistic fixes on the NICClient class
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
12
diff
changeset
|
39 |
DNICHOST = "whois.nic.mil" |
|
5f851e9c196a
Stylistic fixes on the NICClient class
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
12
diff
changeset
|
40 |
GNICHOST = "whois.nic.gov" |
|
5f851e9c196a
Stylistic fixes on the NICClient class
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
12
diff
changeset
|
41 |
ANICHOST = "whois.arin.net" |
|
5f851e9c196a
Stylistic fixes on the NICClient class
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
12
diff
changeset
|
42 |
LNICHOST = "whois.lacnic.net" |
|
5f851e9c196a
Stylistic fixes on the NICClient class
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
12
diff
changeset
|
43 |
RNICHOST = "whois.ripe.net" |
|
5f851e9c196a
Stylistic fixes on the NICClient class
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
12
diff
changeset
|
44 |
PNICHOST = "whois.apnic.net" |
|
5f851e9c196a
Stylistic fixes on the NICClient class
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
12
diff
changeset
|
45 |
MNICHOST = "whois.ra.net" |
|
5f851e9c196a
Stylistic fixes on the NICClient class
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
12
diff
changeset
|
46 |
QNICHOST_TAIL = ".whois-servers.net" |
|
5f851e9c196a
Stylistic fixes on the NICClient class
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
12
diff
changeset
|
47 |
SNICHOST = "whois.6bone.net" |
|
5f851e9c196a
Stylistic fixes on the NICClient class
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
12
diff
changeset
|
48 |
BNICHOST = "whois.registro.br" |
|
5f851e9c196a
Stylistic fixes on the NICClient class
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
12
diff
changeset
|
49 |
NORIDHOST = "whois.norid.no" |
|
5f851e9c196a
Stylistic fixes on the NICClient class
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
12
diff
changeset
|
50 |
IANAHOST = "whois.iana.org" |
|
5f851e9c196a
Stylistic fixes on the NICClient class
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
12
diff
changeset
|
51 |
DENICHOST = "de.whois-servers.net" |
|
5f851e9c196a
Stylistic fixes on the NICClient class
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
12
diff
changeset
|
52 |
DEFAULT_PORT = "nicname" |
| 0 | 53 |
|
|
32
5f851e9c196a
Stylistic fixes on the NICClient class
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
12
diff
changeset
|
54 |
WHOIS_RECURSE = 0x01 |
|
5f851e9c196a
Stylistic fixes on the NICClient class
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
12
diff
changeset
|
55 |
WHOIS_QUICK = 0x02 |
| 0 | 56 |
|
|
32
5f851e9c196a
Stylistic fixes on the NICClient class
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
12
diff
changeset
|
57 |
ip_whois = [LNICHOST, RNICHOST, PNICHOST, BNICHOST] |
| 0 | 58 |
|
|
32
5f851e9c196a
Stylistic fixes on the NICClient class
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
12
diff
changeset
|
59 |
def __init__(self): |
| 0 | 60 |
self.use_qnichost = False |
|
32
5f851e9c196a
Stylistic fixes on the NICClient class
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
12
diff
changeset
|
61 |
|
|
62
fc06c601b875
whois client was using the first whois server in list rather than the whois server associated with the domain we are querying issue #74
Richard Penman
parents:
60
diff
changeset
|
62 |
def findwhois_server(self, buf, hostname, query): |
| 0 | 63 |
"""Search the initial TLD lookup results for the regional-specifc |
64 |
whois server for getting contact details. |
|
65 |
""" |
|
66 |
nhost = None |
|
|
62
fc06c601b875
whois client was using the first whois server in list rather than the whois server associated with the domain we are querying issue #74
Richard Penman
parents:
60
diff
changeset
|
67 |
match = re.compile('Domain Name: ' + query + '\s*.*?Whois Server: (.*?)\s', flags=re.IGNORECASE|re.DOTALL).search(buf)
|
|
fc06c601b875
whois client was using the first whois server in list rather than the whois server associated with the domain we are querying issue #74
Richard Penman
parents:
60
diff
changeset
|
68 |
if match: |
|
fc06c601b875
whois client was using the first whois server in list rather than the whois server associated with the domain we are querying issue #74
Richard Penman
parents:
60
diff
changeset
|
69 |
nhost = match.groups()[0] |
|
32
5f851e9c196a
Stylistic fixes on the NICClient class
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
12
diff
changeset
|
70 |
# if the whois address is domain.tld/something then |
|
5f851e9c196a
Stylistic fixes on the NICClient class
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
12
diff
changeset
|
71 |
# s.connect((hostname, 43)) does not work |
|
6
7dee244ba3ef
fixed builtin whois parser for pwhois.rotld.ro
Richard Baron Penman
parents:
0
diff
changeset
|
72 |
if nhost.count('/') > 0:
|
|
7dee244ba3ef
fixed builtin whois parser for pwhois.rotld.ro
Richard Baron Penman
parents:
0
diff
changeset
|
73 |
nhost = None |
|
62
fc06c601b875
whois client was using the first whois server in list rather than the whois server associated with the domain we are querying issue #74
Richard Penman
parents:
60
diff
changeset
|
74 |
elif hostname == NICClient.ANICHOST: |
| 0 | 75 |
for nichost in NICClient.ip_whois: |
|
62
fc06c601b875
whois client was using the first whois server in list rather than the whois server associated with the domain we are querying issue #74
Richard Penman
parents:
60
diff
changeset
|
76 |
if buf.find(nichost) != -1: |
| 0 | 77 |
nhost = nichost |
78 |
break |
|
79 |
return nhost |
|
|
32
5f851e9c196a
Stylistic fixes on the NICClient class
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
12
diff
changeset
|
80 |
|
|
64
2ed54e885571
only focus whois search after find many results, to avoid search failure
Richard Penman
parents:
62
diff
changeset
|
81 |
def whois(self, query, hostname, flags, many_results=False): |
| 0 | 82 |
"""Perform initial lookup with TLD whois server |
|
6
7dee244ba3ef
fixed builtin whois parser for pwhois.rotld.ro
Richard Baron Penman
parents:
0
diff
changeset
|
83 |
then, if the quick flag is false, search that result |
| 0 | 84 |
for the region-specifc whois server and do a lookup |
85 |
there for contact details |
|
86 |
""" |
|
|
52
1f80f6dec7ac
add socket timeout exception
Jasey Wang <jaseywang@gmail.com>
parents:
45
diff
changeset
|
87 |
try: |
|
62
fc06c601b875
whois client was using the first whois server in list rather than the whois server associated with the domain we are querying issue #74
Richard Penman
parents:
60
diff
changeset
|
88 |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
fc06c601b875
whois client was using the first whois server in list rather than the whois server associated with the domain we are querying issue #74
Richard Penman
parents:
60
diff
changeset
|
89 |
s.settimeout(10) |
|
fc06c601b875
whois client was using the first whois server in list rather than the whois server associated with the domain we are querying issue #74
Richard Penman
parents:
60
diff
changeset
|
90 |
s.connect((hostname, 43)) |
|
fc06c601b875
whois client was using the first whois server in list rather than the whois server associated with the domain we are querying issue #74
Richard Penman
parents:
60
diff
changeset
|
91 |
# end takes bytes as an input |
|
fc06c601b875
whois client was using the first whois server in list rather than the whois server associated with the domain we are querying issue #74
Richard Penman
parents:
60
diff
changeset
|
92 |
queryBytes = None |
|
fc06c601b875
whois client was using the first whois server in list rather than the whois server associated with the domain we are querying issue #74
Richard Penman
parents:
60
diff
changeset
|
93 |
if type(query) is not unicode: |
|
fc06c601b875
whois client was using the first whois server in list rather than the whois server associated with the domain we are querying issue #74
Richard Penman
parents:
60
diff
changeset
|
94 |
query = query.decode('utf-8')
|
|
34
f9da616f15cf
Pass all domains through encode('idna') in NICClient
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
32
diff
changeset
|
95 |
|
|
62
fc06c601b875
whois client was using the first whois server in list rather than the whois server associated with the domain we are querying issue #74
Richard Penman
parents:
60
diff
changeset
|
96 |
if hostname == NICClient.DENICHOST: |
|
fc06c601b875
whois client was using the first whois server in list rather than the whois server associated with the domain we are querying issue #74
Richard Penman
parents:
60
diff
changeset
|
97 |
queryBytes = "-T dn,ace -C UTF-8 " + query |
|
64
2ed54e885571
only focus whois search after find many results, to avoid search failure
Richard Penman
parents:
62
diff
changeset
|
98 |
elif hostname.endswith(NICClient.QNICHOST_TAIL) and many_results: |
|
62
fc06c601b875
whois client was using the first whois server in list rather than the whois server associated with the domain we are querying issue #74
Richard Penman
parents:
60
diff
changeset
|
99 |
queryBytes = '=' + query |
|
fc06c601b875
whois client was using the first whois server in list rather than the whois server associated with the domain we are querying issue #74
Richard Penman
parents:
60
diff
changeset
|
100 |
else: |
|
fc06c601b875
whois client was using the first whois server in list rather than the whois server associated with the domain we are querying issue #74
Richard Penman
parents:
60
diff
changeset
|
101 |
queryBytes = query |
|
fc06c601b875
whois client was using the first whois server in list rather than the whois server associated with the domain we are querying issue #74
Richard Penman
parents:
60
diff
changeset
|
102 |
s.send((queryBytes + "\r\n").encode('idna'))
|
|
fc06c601b875
whois client was using the first whois server in list rather than the whois server associated with the domain we are querying issue #74
Richard Penman
parents:
60
diff
changeset
|
103 |
# recv returns bytes |
|
fc06c601b875
whois client was using the first whois server in list rather than the whois server associated with the domain we are querying issue #74
Richard Penman
parents:
60
diff
changeset
|
104 |
response = b'' |
|
fc06c601b875
whois client was using the first whois server in list rather than the whois server associated with the domain we are querying issue #74
Richard Penman
parents:
60
diff
changeset
|
105 |
while True: |
|
fc06c601b875
whois client was using the first whois server in list rather than the whois server associated with the domain we are querying issue #74
Richard Penman
parents:
60
diff
changeset
|
106 |
d = s.recv(4096) |
|
fc06c601b875
whois client was using the first whois server in list rather than the whois server associated with the domain we are querying issue #74
Richard Penman
parents:
60
diff
changeset
|
107 |
response += d |
|
fc06c601b875
whois client was using the first whois server in list rather than the whois server associated with the domain we are querying issue #74
Richard Penman
parents:
60
diff
changeset
|
108 |
if not d: |
|
fc06c601b875
whois client was using the first whois server in list rather than the whois server associated with the domain we are querying issue #74
Richard Penman
parents:
60
diff
changeset
|
109 |
break |
|
fc06c601b875
whois client was using the first whois server in list rather than the whois server associated with the domain we are querying issue #74
Richard Penman
parents:
60
diff
changeset
|
110 |
s.close() |
|
52
1f80f6dec7ac
add socket timeout exception
Jasey Wang <jaseywang@gmail.com>
parents:
45
diff
changeset
|
111 |
except socket.error as socketerror: |
|
64
2ed54e885571
only focus whois search after find many results, to avoid search failure
Richard Penman
parents:
62
diff
changeset
|
112 |
print 'Socket Error:', socketerror |
| 65 | 113 |
return '' |
114 |
else: |
|
115 |
nhost = None |
|
| 80 | 116 |
response = response.decode('utf-8')
|
| 65 | 117 |
if 'with "=xxx"' in response: |
118 |
return self.whois(query, hostname, flags, True) |
|
119 |
if flags & NICClient.WHOIS_RECURSE and nhost is None: |
|
| 80 | 120 |
nhost = self.findwhois_server(response, hostname, query) |
| 65 | 121 |
if nhost is not None: |
122 |
response += self.whois(query, nhost, 0) |
|
| 80 | 123 |
return response |
|
32
5f851e9c196a
Stylistic fixes on the NICClient class
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
12
diff
changeset
|
124 |
|
| 0 | 125 |
def choose_server(self, domain): |
126 |
"""Choose initial lookup NIC host""" |
|
|
36
af839b9c0ed1
Add support for punycode TLDs
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
34
diff
changeset
|
127 |
if type(domain) is not unicode: |
|
af839b9c0ed1
Add support for punycode TLDs
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
34
diff
changeset
|
128 |
domain = domain.decode('utf-8').encode('idna')
|
|
62
fc06c601b875
whois client was using the first whois server in list rather than the whois server associated with the domain we are querying issue #74
Richard Penman
parents:
60
diff
changeset
|
129 |
if domain.endswith("-NORID"):
|
| 0 | 130 |
return NICClient.NORIDHOST |
131 |
pos = domain.rfind('.')
|
|
|
62
fc06c601b875
whois client was using the first whois server in list rather than the whois server associated with the domain we are querying issue #74
Richard Penman
parents:
60
diff
changeset
|
132 |
if pos == -1: |
| 0 | 133 |
return None |
134 |
tld = domain[pos+1:] |
|
|
62
fc06c601b875
whois client was using the first whois server in list rather than the whois server associated with the domain we are querying issue #74
Richard Penman
parents:
60
diff
changeset
|
135 |
if tld[0].isdigit(): |
| 0 | 136 |
return NICClient.ANICHOST |
137 |
return tld + NICClient.QNICHOST_TAIL |
|
|
32
5f851e9c196a
Stylistic fixes on the NICClient class
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
12
diff
changeset
|
138 |
|
| 0 | 139 |
def whois_lookup(self, options, query_arg, flags): |
|
6
7dee244ba3ef
fixed builtin whois parser for pwhois.rotld.ro
Richard Baron Penman
parents:
0
diff
changeset
|
140 |
"""Main entry point: Perform initial lookup on TLD whois server, |
|
7dee244ba3ef
fixed builtin whois parser for pwhois.rotld.ro
Richard Baron Penman
parents:
0
diff
changeset
|
141 |
or other server to get region-specific whois server, then if quick |
|
7dee244ba3ef
fixed builtin whois parser for pwhois.rotld.ro
Richard Baron Penman
parents:
0
diff
changeset
|
142 |
flag is false, perform a second lookup on the region-specific |
| 0 | 143 |
server for contact records""" |
144 |
nichost = None |
|
|
32
5f851e9c196a
Stylistic fixes on the NICClient class
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
12
diff
changeset
|
145 |
# whoud happen when this function is called by other than main |
| 60 | 146 |
if options is None: |
| 0 | 147 |
options = {}
|
|
32
5f851e9c196a
Stylistic fixes on the NICClient class
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
12
diff
changeset
|
148 |
|
|
62
fc06c601b875
whois client was using the first whois server in list rather than the whois server associated with the domain we are querying issue #74
Richard Penman
parents:
60
diff
changeset
|
149 |
if ('whoishost' not in options or options['whoishost'] is None) \
|
|
fc06c601b875
whois client was using the first whois server in list rather than the whois server associated with the domain we are querying issue #74
Richard Penman
parents:
60
diff
changeset
|
150 |
and ('country' not in options or options['country'] is None):
|
| 0 | 151 |
self.use_qnichost = True |
152 |
options['whoishost'] = NICClient.NICHOST |
|
|
62
fc06c601b875
whois client was using the first whois server in list rather than the whois server associated with the domain we are querying issue #74
Richard Penman
parents:
60
diff
changeset
|
153 |
if not (flags & NICClient.WHOIS_QUICK): |
| 0 | 154 |
flags |= NICClient.WHOIS_RECURSE |
|
32
5f851e9c196a
Stylistic fixes on the NICClient class
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
12
diff
changeset
|
155 |
|
| 60 | 156 |
if 'country' in options and options['country'] is not None: |
|
32
5f851e9c196a
Stylistic fixes on the NICClient class
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
12
diff
changeset
|
157 |
result = self.whois( |
|
5f851e9c196a
Stylistic fixes on the NICClient class
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
12
diff
changeset
|
158 |
query_arg, |
|
5f851e9c196a
Stylistic fixes on the NICClient class
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
12
diff
changeset
|
159 |
options['country'] + NICClient.QNICHOST_TAIL, |
|
5f851e9c196a
Stylistic fixes on the NICClient class
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
12
diff
changeset
|
160 |
flags |
|
5f851e9c196a
Stylistic fixes on the NICClient class
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
12
diff
changeset
|
161 |
) |
| 60 | 162 |
elif self.use_qnichost: |
| 0 | 163 |
nichost = self.choose_server(query_arg) |
|
62
fc06c601b875
whois client was using the first whois server in list rather than the whois server associated with the domain we are querying issue #74
Richard Penman
parents:
60
diff
changeset
|
164 |
if nichost is not None: |
|
6
7dee244ba3ef
fixed builtin whois parser for pwhois.rotld.ro
Richard Baron Penman
parents:
0
diff
changeset
|
165 |
result = self.whois(query_arg, nichost, flags) |
|
45
52ce01013731
Handle experimental lookup method for bad domains
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
36
diff
changeset
|
166 |
else: |
|
52ce01013731
Handle experimental lookup method for bad domains
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
36
diff
changeset
|
167 |
result = '' |
| 0 | 168 |
else: |
169 |
result = self.whois(query_arg, options['whoishost'], flags) |
|
170 |
return result |
|
|
32
5f851e9c196a
Stylistic fixes on the NICClient class
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
12
diff
changeset
|
171 |
|
|
5f851e9c196a
Stylistic fixes on the NICClient class
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
12
diff
changeset
|
172 |
|
| 0 | 173 |
def parse_command_line(argv): |
174 |
"""Options handling mostly follows the UNIX whois(1) man page, except |
|
175 |
long-form options can also be used. |
|
176 |
""" |
|
177 |
flags = 0 |
|
|
32
5f851e9c196a
Stylistic fixes on the NICClient class
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
12
diff
changeset
|
178 |
|
| 0 | 179 |
usage = "usage: %prog [options] name" |
|
32
5f851e9c196a
Stylistic fixes on the NICClient class
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
12
diff
changeset
|
180 |
|
| 0 | 181 |
parser = optparse.OptionParser(add_help_option=False, usage=usage) |
|
6
7dee244ba3ef
fixed builtin whois parser for pwhois.rotld.ro
Richard Baron Penman
parents:
0
diff
changeset
|
182 |
parser.add_option("-a", "--arin", action="store_const",
|
| 0 | 183 |
const=NICClient.ANICHOST, dest="whoishost", |
184 |
help="Lookup using host " + NICClient.ANICHOST) |
|
|
6
7dee244ba3ef
fixed builtin whois parser for pwhois.rotld.ro
Richard Baron Penman
parents:
0
diff
changeset
|
185 |
parser.add_option("-A", "--apnic", action="store_const",
|
| 0 | 186 |
const=NICClient.PNICHOST, dest="whoishost", |
187 |
help="Lookup using host " + NICClient.PNICHOST) |
|
|
6
7dee244ba3ef
fixed builtin whois parser for pwhois.rotld.ro
Richard Baron Penman
parents:
0
diff
changeset
|
188 |
parser.add_option("-b", "--abuse", action="store_const",
|
| 0 | 189 |
const=NICClient.ABUSEHOST, dest="whoishost", |
190 |
help="Lookup using host " + NICClient.ABUSEHOST) |
|
|
6
7dee244ba3ef
fixed builtin whois parser for pwhois.rotld.ro
Richard Baron Penman
parents:
0
diff
changeset
|
191 |
parser.add_option("-c", "--country", action="store",
|
| 0 | 192 |
type="string", dest="country", |
193 |
help="Lookup using country-specific NIC") |
|
|
6
7dee244ba3ef
fixed builtin whois parser for pwhois.rotld.ro
Richard Baron Penman
parents:
0
diff
changeset
|
194 |
parser.add_option("-d", "--mil", action="store_const",
|
| 0 | 195 |
const=NICClient.DNICHOST, dest="whoishost", |
196 |
help="Lookup using host " + NICClient.DNICHOST) |
|
|
6
7dee244ba3ef
fixed builtin whois parser for pwhois.rotld.ro
Richard Baron Penman
parents:
0
diff
changeset
|
197 |
parser.add_option("-g", "--gov", action="store_const",
|
| 0 | 198 |
const=NICClient.GNICHOST, dest="whoishost", |
199 |
help="Lookup using host " + NICClient.GNICHOST) |
|
|
6
7dee244ba3ef
fixed builtin whois parser for pwhois.rotld.ro
Richard Baron Penman
parents:
0
diff
changeset
|
200 |
parser.add_option("-h", "--host", action="store",
|
| 0 | 201 |
type="string", dest="whoishost", |
|
32
5f851e9c196a
Stylistic fixes on the NICClient class
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
12
diff
changeset
|
202 |
help="Lookup using specified whois host") |
|
6
7dee244ba3ef
fixed builtin whois parser for pwhois.rotld.ro
Richard Baron Penman
parents:
0
diff
changeset
|
203 |
parser.add_option("-i", "--nws", action="store_const",
|
| 0 | 204 |
const=NICClient.INICHOST, dest="whoishost", |
205 |
help="Lookup using host " + NICClient.INICHOST) |
|
|
6
7dee244ba3ef
fixed builtin whois parser for pwhois.rotld.ro
Richard Baron Penman
parents:
0
diff
changeset
|
206 |
parser.add_option("-I", "--iana", action="store_const",
|
| 0 | 207 |
const=NICClient.IANAHOST, dest="whoishost", |
208 |
help="Lookup using host " + NICClient.IANAHOST) |
|
|
6
7dee244ba3ef
fixed builtin whois parser for pwhois.rotld.ro
Richard Baron Penman
parents:
0
diff
changeset
|
209 |
parser.add_option("-l", "--lcanic", action="store_const",
|
| 0 | 210 |
const=NICClient.LNICHOST, dest="whoishost", |
211 |
help="Lookup using host " + NICClient.LNICHOST) |
|
|
6
7dee244ba3ef
fixed builtin whois parser for pwhois.rotld.ro
Richard Baron Penman
parents:
0
diff
changeset
|
212 |
parser.add_option("-m", "--ra", action="store_const",
|
| 0 | 213 |
const=NICClient.MNICHOST, dest="whoishost", |
214 |
help="Lookup using host " + NICClient.MNICHOST) |
|
|
6
7dee244ba3ef
fixed builtin whois parser for pwhois.rotld.ro
Richard Baron Penman
parents:
0
diff
changeset
|
215 |
parser.add_option("-p", "--port", action="store",
|
| 0 | 216 |
type="int", dest="port", |
217 |
help="Lookup using specified tcp port") |
|
|
6
7dee244ba3ef
fixed builtin whois parser for pwhois.rotld.ro
Richard Baron Penman
parents:
0
diff
changeset
|
218 |
parser.add_option("-Q", "--quick", action="store_true",
|
|
32
5f851e9c196a
Stylistic fixes on the NICClient class
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
12
diff
changeset
|
219 |
dest="b_quicklookup", |
|
5f851e9c196a
Stylistic fixes on the NICClient class
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
12
diff
changeset
|
220 |
help="Perform quick lookup") |
|
6
7dee244ba3ef
fixed builtin whois parser for pwhois.rotld.ro
Richard Baron Penman
parents:
0
diff
changeset
|
221 |
parser.add_option("-r", "--ripe", action="store_const",
|
| 0 | 222 |
const=NICClient.RNICHOST, dest="whoishost", |
223 |
help="Lookup using host " + NICClient.RNICHOST) |
|
|
6
7dee244ba3ef
fixed builtin whois parser for pwhois.rotld.ro
Richard Baron Penman
parents:
0
diff
changeset
|
224 |
parser.add_option("-R", "--ru", action="store_const",
|
| 0 | 225 |
const="ru", dest="country", |
226 |
help="Lookup Russian NIC") |
|
|
6
7dee244ba3ef
fixed builtin whois parser for pwhois.rotld.ro
Richard Baron Penman
parents:
0
diff
changeset
|
227 |
parser.add_option("-6", "--6bone", action="store_const",
|
| 0 | 228 |
const=NICClient.SNICHOST, dest="whoishost", |
229 |
help="Lookup using host " + NICClient.SNICHOST) |
|
230 |
parser.add_option("-?", "--help", action="help")
|
|
231 |
||
232 |
return parser.parse_args(argv) |
|
|
32
5f851e9c196a
Stylistic fixes on the NICClient class
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
12
diff
changeset
|
233 |
|
|
62
fc06c601b875
whois client was using the first whois server in list rather than the whois server associated with the domain we are querying issue #74
Richard Penman
parents:
60
diff
changeset
|
234 |
|
| 0 | 235 |
if __name__ == "__main__": |
236 |
flags = 0 |
|
237 |
nic_client = NICClient() |
|
|
62
fc06c601b875
whois client was using the first whois server in list rather than the whois server associated with the domain we are querying issue #74
Richard Penman
parents:
60
diff
changeset
|
238 |
options, args = parse_command_line(sys.argv) |
|
fc06c601b875
whois client was using the first whois server in list rather than the whois server associated with the domain we are querying issue #74
Richard Penman
parents:
60
diff
changeset
|
239 |
if options.b_quicklookup: |
|
32
5f851e9c196a
Stylistic fixes on the NICClient class
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
12
diff
changeset
|
240 |
flags = flags | NICClient.WHOIS_QUICK |
| 60 | 241 |
print nic_client.whois_lookup(options.__dict__, args[1], flags) |