| author | Evgeni Kunev <evgeni.kunev@gmail.com> |
| Mon, 11 Aug 2014 15:23:49 +0300 | |
| changeset 26 | e0b929723473 |
| parent 24 | 16f17c400a70 |
| child 27 | 2afe979e4f4a |
| permissions | -rw-r--r-- |
| 0 | 1 |
# parser.py - Module for parsing whois response data |
2 |
# Copyright (c) 2008 Andrey Petrov |
|
3 |
# |
|
4 |
# This module is part of pywhois and is released under |
|
5 |
# the MIT license: http://www.opensource.org/licenses/mit-license.php |
|
6 |
||
7 |
import re |
|
| 2 | 8 |
from datetime import datetime |
| 0 | 9 |
|
10 |
||
11 |
class PywhoisError(Exception): |
|
12 |
pass |
|
13 |
||
14 |
||
| 5 | 15 |
def cast_date(s): |
16 |
"""Convert any date string found in WHOIS to a datetime object. |
|
| 0 | 17 |
""" |
18 |
known_formats = [ |
|
19 |
'%d-%b-%Y', # 02-jan-2000 |
|
20 |
'%Y-%m-%d', # 2000-01-02 |
|
| 13 | 21 |
'%d.%m.%Y', # 2.1.2000 |
| 5 | 22 |
'%Y.%m.%d', # 2000.01.02 |
23 |
'%Y/%m/%d', # 2000/01/02 |
|
| 21 | 24 |
'%d/%m/%Y', # 02/01/2013 |
| 19 | 25 |
'%Y. %m. %d.', # 2000. 01. 02. |
| 18 | 26 |
'%Y.%m.%d %H:%M:%S', # 2014.03.08 10:28:24 |
| 0 | 27 |
'%d-%b-%Y %H:%M:%S %Z', # 24-Jul-2009 13:20:03 UTC |
28 |
'%a %b %d %H:%M:%S %Z %Y', # Tue Jun 21 23:59:59 GMT 2011 |
|
29 |
'%Y-%m-%dT%H:%M:%SZ', # 2007-01-26T19:10:31Z |
|
| 24 | 30 |
'%Y-%m-%dT%H:%M:%S%z', # 2013-12-06T08:17:22-0800 |
| 16 | 31 |
'%Y-%m-%d %H:%M:%SZ', # 2000-08-22 18:55:20Z |
| 17 | 32 |
'%Y-%m-%d %H:%M:%S', # 2000-08-22 18:55:20 |
| 16 | 33 |
'%d %b %Y %H:%M:%S', # 08 Apr 2013 05:44:00 |
|
26
e0b929723473
Add expiry_date regex for .bg domains
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
24
diff
changeset
|
34 |
'%d/%m/%Y %H:%M:%S.%f %Z', # 23/04/2015 12:00:07.619546 EEST |
| 0 | 35 |
] |
36 |
||
| 5 | 37 |
for known_format in known_formats: |
| 0 | 38 |
try: |
| 17 | 39 |
s = datetime.strptime(s.strip(), known_format) |
40 |
break |
|
| 12 | 41 |
except ValueError as e: |
| 0 | 42 |
pass # Wrong format, keep trying |
| 5 | 43 |
return s |
| 0 | 44 |
|
45 |
||
46 |
class WhoisEntry(object): |
|
47 |
"""Base class for parsing a Whois entries. |
|
48 |
""" |
|
49 |
# regular expressions to extract domain data from whois profile |
|
50 |
# child classes will override this |
|
51 |
_regex = {
|
|
52 |
'domain_name': 'Domain Name:\s?(.+)', |
|
53 |
'registrar': 'Registrar:\s?(.+)', |
|
54 |
'whois_server': 'Whois Server:\s?(.+)', |
|
55 |
'referral_url': 'Referral URL:\s?(.+)', # http url of whois_server |
|
56 |
'updated_date': 'Updated Date:\s?(.+)', |
|
57 |
'creation_date': 'Creation Date:\s?(.+)', |
|
| 23 | 58 |
'expiration_date': 'Expir\w+ Date:\s?(.+)', |
| 0 | 59 |
'name_servers': 'Name Server:\s?(.+)', # list of name servers |
60 |
'status': 'Status:\s?(.+)', # list of statuses |
|
61 |
'emails': '[\w.-]+@[\w.-]+\.[\w]{2,4}', # list of email addresses
|
|
62 |
} |
|
63 |
||
64 |
def __init__(self, domain, text, regex=None): |
|
65 |
self.domain = domain |
|
66 |
self.text = text |
|
67 |
if regex is not None: |
|
68 |
self._regex = regex |
|
69 |
||
70 |
||
71 |
def __getattr__(self, attr): |
|
72 |
"""The first time an attribute is called it will be calculated here. |
|
73 |
The attribute is then set to be accessed directly by subsequent calls. |
|
74 |
""" |
|
75 |
whois_regex = self._regex.get(attr) |
|
76 |
if whois_regex: |
|
| 14 | 77 |
values = [] |
78 |
for value in re.findall(whois_regex, self.text, re.IGNORECASE): |
|
79 |
if isinstance(value, basestring): |
|
80 |
# try casting to date format |
|
81 |
value = cast_date(value.strip()) |
|
| 20 | 82 |
if value and value not in values: |
| 16 | 83 |
# avoid duplicates |
84 |
values.append(value) |
|
| 5 | 85 |
if len(values) == 1: |
86 |
values = values[0] |
|
| 23 | 87 |
elif not values: |
88 |
values = None |
|
| 16 | 89 |
|
| 5 | 90 |
setattr(self, attr, values) |
| 0 | 91 |
return getattr(self, attr) |
92 |
else: |
|
93 |
raise KeyError('Unknown attribute: %s' % attr)
|
|
94 |
||
95 |
def __str__(self): |
|
96 |
"""Print all whois properties of domain |
|
97 |
""" |
|
98 |
return '\n'.join('%s: %s' % (attr, str(getattr(self, attr))) for attr in self.attrs())
|
|
99 |
||
100 |
||
| 24 | 101 |
def __getstate__(self): |
102 |
"""To support pickling |
|
103 |
""" |
|
104 |
return self.__dict__ |
|
105 |
||
106 |
def __setstate__(self, state): |
|
107 |
self.__dict__ = state |
|
108 |
||
109 |
||
| 0 | 110 |
def attrs(self): |
111 |
"""Return list of attributes that can be extracted for this domain |
|
112 |
""" |
|
113 |
return sorted(self._regex.keys()) |
|
114 |
||
115 |
||
116 |
@staticmethod |
|
117 |
def load(domain, text): |
|
118 |
"""Given whois output in ``text``, return an instance of ``WhoisEntry`` that represents its parsed contents. |
|
119 |
""" |
|
120 |
if text.strip() == 'No whois server is known for this kind of object.': |
|
121 |
raise PywhoisError(text) |
|
122 |
||
| 10 | 123 |
if domain.endswith('.com'):
|
| 0 | 124 |
return WhoisCom(domain, text) |
| 10 | 125 |
elif domain.endswith('.net'):
|
| 0 | 126 |
return WhoisNet(domain, text) |
| 10 | 127 |
elif domain.endswith('.org'):
|
| 0 | 128 |
return WhoisOrg(domain, text) |
| 10 | 129 |
elif domain.endswith('.name'):
|
| 0 | 130 |
return WhoisName(domain, text) |
| 10 | 131 |
elif domain.endswith('.me'):
|
132 |
return WhoisMe(domain, text) |
|
| 17 | 133 |
elif domain.endswith('.au'):
|
134 |
return WhoisAU(domain, text) |
|
| 10 | 135 |
elif domain.endswith('.ru'):
|
136 |
return WhoisRu(domain, text) |
|
137 |
elif domain.endswith('.us'):
|
|
| 0 | 138 |
return WhoisUs(domain, text) |
| 10 | 139 |
elif domain.endswith('.uk'):
|
| 0 | 140 |
return WhoisUk(domain, text) |
| 10 | 141 |
elif domain.endswith('.fr'):
|
| 4 | 142 |
return WhoisFr(domain, text) |
| 10 | 143 |
elif domain.endswith('.fi'):
|
| 2 | 144 |
return WhoisFi(domain, text) |
| 10 | 145 |
elif domain.endswith('.jp'):
|
| 5 | 146 |
return WhoisJp(domain, text) |
| 11 | 147 |
elif domain.endswith('.pl'):
|
148 |
return WhoisPl(domain, text) |
|
| 15 | 149 |
elif domain.endswith('.br'):
|
| 21 | 150 |
return WhoisBr(domain, text) |
| 20 | 151 |
elif domain.endswith('.eu'):
|
| 21 | 152 |
return WhoisEu(domain, text) |
| 19 | 153 |
elif domain.endswith('.kr'):
|
| 21 | 154 |
return WhoisKr(domain, text) |
155 |
elif domain.endswith('.pt'):
|
|
156 |
return WhoisPt(domain, text) |
|
|
26
e0b929723473
Add expiry_date regex for .bg domains
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
24
diff
changeset
|
157 |
elif domain.endswith('.bg'):
|
|
e0b929723473
Add expiry_date regex for .bg domains
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
24
diff
changeset
|
158 |
return WhoisBg(domain, text) |
| 0 | 159 |
else: |
160 |
return WhoisEntry(domain, text) |
|
161 |
||
162 |
||
163 |
||
164 |
class WhoisCom(WhoisEntry): |
|
165 |
"""Whois parser for .com domains |
|
166 |
""" |
|
167 |
def __init__(self, domain, text): |
|
168 |
if 'No match for "' in text: |
|
169 |
raise PywhoisError(text) |
|
170 |
else: |
|
171 |
WhoisEntry.__init__(self, domain, text) |
|
172 |
||
| 4 | 173 |
|
| 0 | 174 |
class WhoisNet(WhoisEntry): |
175 |
"""Whois parser for .net domains |
|
176 |
""" |
|
177 |
def __init__(self, domain, text): |
|
178 |
if 'No match for "' in text: |
|
179 |
raise PywhoisError(text) |
|
180 |
else: |
|
181 |
WhoisEntry.__init__(self, domain, text) |
|
182 |
||
| 4 | 183 |
|
| 0 | 184 |
class WhoisOrg(WhoisEntry): |
185 |
"""Whois parser for .org domains |
|
186 |
""" |
|
187 |
def __init__(self, domain, text): |
|
188 |
if text.strip() == 'NOT FOUND': |
|
189 |
raise PywhoisError(text) |
|
190 |
else: |
|
191 |
WhoisEntry.__init__(self, domain, text) |
|
192 |
||
| 4 | 193 |
|
| 0 | 194 |
class WhoisRu(WhoisEntry): |
195 |
"""Whois parser for .ru domains |
|
196 |
""" |
|
197 |
regex = {
|
|
198 |
'domain_name': 'domain:\s*(.+)', |
|
199 |
'registrar': 'registrar:\s*(.+)', |
|
200 |
'creation_date': 'created:\s*(.+)', |
|
201 |
'expiration_date': 'paid-till:\s*(.+)', |
|
202 |
'name_servers': 'nserver:\s*(.+)', # list of name servers |
|
203 |
'status': 'state:\s*(.+)', # list of statuses |
|
204 |
'emails': '[\w.-]+@[\w.-]+\.[\w]{2,4}', # list of email addresses
|
|
205 |
} |
|
206 |
||
207 |
def __init__(self, domain, text): |
|
208 |
if text.strip() == 'No entries found': |
|
209 |
raise PywhoisError(text) |
|
210 |
else: |
|
211 |
WhoisEntry.__init__(self, domain, text, self.regex) |
|
212 |
||
| 4 | 213 |
|
| 0 | 214 |
class WhoisName(WhoisEntry): |
215 |
"""Whois parser for .name domains |
|
216 |
""" |
|
217 |
regex = {
|
|
218 |
'domain_name_id': 'Domain Name ID:\s*(.+)', |
|
219 |
'domain_name': 'Domain Name:\s*(.+)', |
|
220 |
'registrar_id': 'Sponsoring Registrar ID:\s*(.+)', |
|
221 |
'registrar': 'Sponsoring Registrar:\s*(.+)', |
|
222 |
'registrant_id': 'Registrant ID:\s*(.+)', |
|
223 |
'admin_id': 'Admin ID:\s*(.+)', |
|
224 |
'technical_id': 'Tech ID:\s*(.+)', |
|
225 |
'billing_id': 'Billing ID:\s*(.+)', |
|
226 |
'creation_date': 'Created On:\s*(.+)', |
|
227 |
'expiration_date': 'Expires On:\s*(.+)', |
|
228 |
'updated_date': 'Updated On:\s*(.+)', |
|
229 |
'name_server_ids': 'Name Server ID:\s*(.+)', # list of name server ids |
|
230 |
'name_servers': 'Name Server:\s*(.+)', # list of name servers |
|
231 |
'status': 'Domain Status:\s*(.+)', # list of statuses |
|
232 |
} |
|
233 |
def __init__(self, domain, text): |
|
234 |
if 'No match.' in text: |
|
235 |
raise PywhoisError(text) |
|
236 |
else: |
|
237 |
WhoisEntry.__init__(self, domain, text, self.regex) |
|
| 4 | 238 |
|
239 |
||
| 0 | 240 |
class WhoisUs(WhoisEntry): |
241 |
"""Whois parser for .us domains |
|
242 |
""" |
|
243 |
regex = {
|
|
244 |
'domain_name': 'Domain Name:\s*(.+)', |
|
245 |
'domain__id': 'Domain ID:\s*(.+)', |
|
246 |
'registrar': 'Sponsoring Registrar:\s*(.+)', |
|
247 |
'registrar_id': 'Sponsoring Registrar IANA ID:\s*(.+)', |
|
248 |
'registrar_url': 'Registrar URL \(registration services\):\s*(.+)', |
|
249 |
'status': 'Domain Status:\s*(.+)', # list of statuses |
|
250 |
'registrant_id': 'Registrant ID:\s*(.+)', |
|
251 |
'registrant_name': 'Registrant Name:\s*(.+)', |
|
252 |
'registrant_address1': 'Registrant Address1:\s*(.+)', |
|
253 |
'registrant_address2': 'Registrant Address2:\s*(.+)', |
|
254 |
'registrant_city': 'Registrant City:\s*(.+)', |
|
255 |
'registrant_state_province': 'Registrant State/Province:\s*(.+)', |
|
256 |
'registrant_postal_code': 'Registrant Postal Code:\s*(.+)', |
|
257 |
'registrant_country': 'Registrant Country:\s*(.+)', |
|
258 |
'registrant_country_code': 'Registrant Country Code:\s*(.+)', |
|
259 |
'registrant_phone_number': 'Registrant Phone Number:\s*(.+)', |
|
260 |
'registrant_email': 'Registrant Email:\s*(.+)', |
|
261 |
'registrant_application_purpose': 'Registrant Application Purpose:\s*(.+)', |
|
262 |
'registrant_nexus_category': 'Registrant Nexus Category:\s*(.+)', |
|
263 |
'admin_id': 'Administrative Contact ID:\s*(.+)', |
|
264 |
'admin_name': 'Administrative Contact Name:\s*(.+)', |
|
265 |
'admin_address1': 'Administrative Contact Address1:\s*(.+)', |
|
266 |
'admin_address2': 'Administrative Contact Address2:\s*(.+)', |
|
267 |
'admin_city': 'Administrative Contact City:\s*(.+)', |
|
268 |
'admin_state_province': 'Administrative Contact State/Province:\s*(.+)', |
|
269 |
'admin_postal_code': 'Administrative Contact Postal Code:\s*(.+)', |
|
270 |
'admin_country': 'Administrative Contact Country:\s*(.+)', |
|
271 |
'admin_country_code': 'Administrative Contact Country Code:\s*(.+)', |
|
272 |
'admin_phone_number': 'Administrative Contact Phone Number:\s*(.+)', |
|
273 |
'admin_email': 'Administrative Contact Email:\s*(.+)', |
|
274 |
'admin_application_purpose': 'Administrative Application Purpose:\s*(.+)', |
|
275 |
'admin_nexus_category': 'Administrative Nexus Category:\s*(.+)', |
|
276 |
'billing_id': 'Billing Contact ID:\s*(.+)', |
|
277 |
'billing_name': 'Billing Contact Name:\s*(.+)', |
|
278 |
'billing_address1': 'Billing Contact Address1:\s*(.+)', |
|
279 |
'billing_address2': 'Billing Contact Address2:\s*(.+)', |
|
280 |
'billing_city': 'Billing Contact City:\s*(.+)', |
|
281 |
'billing_state_province': 'Billing Contact State/Province:\s*(.+)', |
|
282 |
'billing_postal_code': 'Billing Contact Postal Code:\s*(.+)', |
|
283 |
'billing_country': 'Billing Contact Country:\s*(.+)', |
|
284 |
'billing_country_code': 'Billing Contact Country Code:\s*(.+)', |
|
285 |
'billing_phone_number': 'Billing Contact Phone Number:\s*(.+)', |
|
286 |
'billing_email': 'Billing Contact Email:\s*(.+)', |
|
287 |
'billing_application_purpose': 'Billing Application Purpose:\s*(.+)', |
|
288 |
'billing_nexus_category': 'Billing Nexus Category:\s*(.+)', |
|
289 |
'tech_id': 'Technical Contact ID:\s*(.+)', |
|
290 |
'tech_name': 'Technical Contact Name:\s*(.+)', |
|
291 |
'tech_address1': 'Technical Contact Address1:\s*(.+)', |
|
292 |
'tech_address2': 'Technical Contact Address2:\s*(.+)', |
|
293 |
'tech_city': 'Technical Contact City:\s*(.+)', |
|
294 |
'tech_state_province': 'Technical Contact State/Province:\s*(.+)', |
|
295 |
'tech_postal_code': 'Technical Contact Postal Code:\s*(.+)', |
|
296 |
'tech_country': 'Technical Contact Country:\s*(.+)', |
|
297 |
'tech_country_code': 'Technical Contact Country Code:\s*(.+)', |
|
298 |
'tech_phone_number': 'Technical Contact Phone Number:\s*(.+)', |
|
299 |
'tech_email': 'Technical Contact Email:\s*(.+)', |
|
300 |
'tech_application_purpose': 'Technical Application Purpose:\s*(.+)', |
|
301 |
'tech_nexus_category': 'Technical Nexus Category:\s*(.+)', |
|
302 |
'name_servers': 'Name Server:\s*(.+)', # list of name servers |
|
303 |
'created_by_registrar': 'Created by Registrar:\s*(.+)', |
|
304 |
'last_updated_by_registrar': 'Last Updated by Registrar:\s*(.+)', |
|
305 |
'creation_date': 'Domain Registration Date:\s*(.+)', |
|
306 |
'expiration_date': 'Domain Expiration Date:\s*(.+)', |
|
307 |
'updated_date': 'Domain Last Updated Date:\s*(.+)', |
|
308 |
} |
|
309 |
def __init__(self, domain, text): |
|
310 |
if 'Not found:' in text: |
|
311 |
raise PywhoisError(text) |
|
312 |
else: |
|
313 |
WhoisEntry.__init__(self, domain, text, self.regex) |
|
| 11 | 314 |
|
315 |
||
316 |
class WhoisPl(WhoisEntry): |
|
| 22 | 317 |
"""Whois parser for .pl domains |
| 11 | 318 |
""" |
319 |
regex = {
|
|
320 |
'domain_name': 'DOMAIN NAME:\s*(.+)\n', |
|
321 |
'registrar': 'REGISTRAR:\n\s*(.+)', |
|
322 |
'registrar_url': 'URL:\s*(.+)', # not available |
|
323 |
'status': 'Registration status:\n\s*(.+)', # not available |
|
324 |
'registrant_name': 'Registrant:\n\s*(.+)', # not available |
|
325 |
'creation_date': 'created:\s*(.+)\n', |
|
326 |
'expiration_date': 'renewal date:\s*(.+)', |
|
327 |
'updated_date': 'last modified:\s*(.+)\n', |
|
328 |
} |
|
329 |
def __init__(self, domain, text): |
|
330 |
if 'Not found:' in text: |
|
331 |
raise PywhoisError(text) |
|
332 |
else: |
|
333 |
WhoisEntry.__init__(self, domain, text, self.regex) |
|
334 |
||
| 5 | 335 |
|
| 0 | 336 |
class WhoisMe(WhoisEntry): |
337 |
"""Whois parser for .me domains |
|
338 |
""" |
|
339 |
regex = {
|
|
340 |
'domain_id': 'Domain ID:(.+)', |
|
341 |
'domain_name': 'Domain Name:(.+)', |
|
342 |
'creation_date': 'Domain Create Date:(.+)', |
|
343 |
'updated_date': 'Domain Last Updated Date:(.+)', |
|
344 |
'expiration_date': 'Domain Expiration Date:(.+)', |
|
345 |
'transfer_date': 'Last Transferred Date:(.+)', |
|
346 |
'trademark_name': 'Trademark Name:(.+)', |
|
347 |
'trademark_country': 'Trademark Country:(.+)', |
|
348 |
'trademark_number': 'Trademark Number:(.+)', |
|
349 |
'trademark_application_date': 'Date Trademark Applied For:(.+)', |
|
350 |
'trademark_registration_date': 'Date Trademark Registered:(.+)', |
|
351 |
'registrar': 'Sponsoring Registrar:(.+)', |
|
352 |
'created_by': 'Created by:(.+)', |
|
353 |
'updated_by': 'Last Updated by Registrar:(.+)', |
|
354 |
'status': 'Domain Status:(.+)', # list of statuses |
|
355 |
'registrant_id': 'Registrant ID:(.+)', |
|
356 |
'registrant_name': 'Registrant Name:(.+)', |
|
357 |
'registrant_org': 'Registrant Organization:(.+)', |
|
358 |
'registrant_address': 'Registrant Address:(.+)', |
|
359 |
'registrant_address2': 'Registrant Address2:(.+)', |
|
360 |
'registrant_address3': 'Registrant Address3:(.+)', |
|
361 |
'registrant_city': 'Registrant City:(.+)', |
|
362 |
'registrant_state_province': 'Registrant State/Province:(.+)', |
|
363 |
'registrant_country': 'Registrant Country/Economy:(.+)', |
|
364 |
'registrant_postal_code': 'Registrant Postal Code:(.+)', |
|
365 |
'registrant_phone': 'Registrant Phone:(.+)', |
|
366 |
'registrant_phone_ext': 'Registrant Phone Ext\.:(.+)', |
|
367 |
'registrant_fax': 'Registrant FAX:(.+)', |
|
368 |
'registrant_fax_ext': 'Registrant FAX Ext\.:(.+)', |
|
369 |
'registrant_email': 'Registrant E-mail:(.+)', |
|
370 |
'admin_id': 'Admin ID:(.+)', |
|
371 |
'admin_name': 'Admin Name:(.+)', |
|
372 |
'admin_org': 'Admin Organization:(.+)', |
|
373 |
'admin_address': 'Admin Address:(.+)', |
|
374 |
'admin_address2': 'Admin Address2:(.+)', |
|
375 |
'admin_address3': 'Admin Address3:(.+)', |
|
376 |
'admin_city': 'Admin City:(.+)', |
|
377 |
'admin_state_province': 'Admin State/Province:(.+)', |
|
378 |
'admin_country': 'Admin Country/Economy:(.+)', |
|
379 |
'admin_postal_code': 'Admin Postal Code:(.+)', |
|
380 |
'admin_phone': 'Admin Phone:(.+)', |
|
381 |
'admin_phone_ext': 'Admin Phone Ext\.:(.+)', |
|
382 |
'admin_fax': 'Admin FAX:(.+)', |
|
383 |
'admin_fax_ext': 'Admin FAX Ext\.:(.+)', |
|
384 |
'admin_email': 'Admin E-mail:(.+)', |
|
385 |
'tech_id': 'Tech ID:(.+)', |
|
386 |
'tech_name': 'Tech Name:(.+)', |
|
387 |
'tech_org': 'Tech Organization:(.+)', |
|
388 |
'tech_address': 'Tech Address:(.+)', |
|
389 |
'tech_address2': 'Tech Address2:(.+)', |
|
390 |
'tech_address3': 'Tech Address3:(.+)', |
|
391 |
'tech_city': 'Tech City:(.+)', |
|
392 |
'tech_state_province': 'Tech State/Province:(.+)', |
|
393 |
'tech_country': 'Tech Country/Economy:(.+)', |
|
394 |
'tech_postal_code': 'Tech Postal Code:(.+)', |
|
395 |
'tech_phone': 'Tech Phone:(.+)', |
|
396 |
'tech_phone_ext': 'Tech Phone Ext\.:(.+)', |
|
397 |
'tech_fax': 'Tech FAX:(.+)', |
|
398 |
'tech_fax_ext': 'Tech FAX Ext\.:(.+)', |
|
399 |
'tech_email': 'Tech E-mail:(.+)', |
|
400 |
'name_servers': 'Nameservers:(.+)', # list of name servers |
|
401 |
} |
|
402 |
def __init__(self, domain, text): |
|
403 |
if 'NOT FOUND' in text: |
|
404 |
raise PywhoisError(text) |
|
405 |
else: |
|
406 |
WhoisEntry.__init__(self, domain, text, self.regex) |
|
407 |
||
| 5 | 408 |
|
| 0 | 409 |
class WhoisUk(WhoisEntry): |
410 |
"""Whois parser for .uk domains |
|
411 |
""" |
|
412 |
regex = {
|
|
413 |
'domain_name': 'Domain name:\n\s*(.+)', |
|
414 |
'registrar': 'Registrar:\n\s*(.+)', |
|
415 |
'registrar_url': 'URL:\s*(.+)', |
|
416 |
'status': 'Registration status:\n\s*(.+)', # list of statuses |
|
417 |
'registrant_name': 'Registrant:\n\s*(.+)', |
|
418 |
'creation_date': 'Registered on:\s*(.+)', |
|
| 5 | 419 |
'expiration_date': 'Expiry date:\s*(.+)', |
| 0 | 420 |
'updated_date': 'Last updated:\s*(.+)', |
| 3 | 421 |
'name_servers': 'Name servers:\s*(.+)', |
| 0 | 422 |
} |
423 |
def __init__(self, domain, text): |
|
424 |
if 'Not found:' in text: |
|
425 |
raise PywhoisError(text) |
|
426 |
else: |
|
427 |
WhoisEntry.__init__(self, domain, text, self.regex) |
|
| 2 | 428 |
|
| 4 | 429 |
|
430 |
class WhoisFr(WhoisEntry): |
|
431 |
"""Whois parser for .fr domains |
|
432 |
""" |
|
433 |
regex = {
|
|
434 |
'domain_name': 'domain:\s*(.+)', |
|
435 |
'registrar': 'registrar:\s*(.+)', |
|
436 |
'creation_date': 'created:\s*(.+)', |
|
437 |
'expiration_date': 'anniversary:\s*(.+)', |
|
438 |
'name_servers': 'nserver:\s*(.+)', # list of name servers |
|
439 |
'status': 'status:\s*(.+)', # list of statuses |
|
440 |
'emails': '[\w.-]+@[\w.-]+\.[\w]{2,4}', # list of email addresses
|
|
441 |
'updated_date': 'last-update:\s*(.+)', |
|
442 |
} |
|
443 |
||
444 |
def __init__(self, domain, text): |
|
445 |
if text.strip() == 'No entries found': |
|
446 |
raise PywhoisError(text) |
|
447 |
else: |
|
448 |
WhoisEntry.__init__(self, domain, text, self.regex) |
|
449 |
||
450 |
||
| 2 | 451 |
class WhoisFi(WhoisEntry): |
452 |
"""Whois parser for .fi domains |
|
453 |
""" |
|
454 |
regex = {
|
|
455 |
'domain_name': 'domain:\s*([\S]+)', |
|
456 |
'registrant_name': 'descr:\s*([\S\ ]+)', |
|
457 |
'registrant_address': 'address:\s*([\S\ ]+)', |
|
458 |
'registrant_phone': 'phone:\s*([\S\ ]+)', |
|
459 |
'status': 'status:\s*([\S]+)', # list of statuses |
|
460 |
'creation_date': 'created:\s*([\S]+)', |
|
461 |
'updated_date': 'modified:\s*([\S]+)', |
|
462 |
'expiration_date': 'expires:\s*([\S]+)', |
|
| 13 | 463 |
'name_servers': 'nserver:\s*([\S]+) \[\S+\]', # list of name servers |
464 |
'name_server_statuses': 'nserver:\s*([\S]+) \[(\S+)\]', # list of name servers and statuses |
|
465 |
'dnssec': 'dnssec:\s*([\S]+)', |
|
| 2 | 466 |
} |
467 |
def __init__(self, domain, text): |
|
| 13 | 468 |
if 'Domain not ' in text: |
| 2 | 469 |
raise PywhoisError(text) |
470 |
else: |
|
471 |
WhoisEntry.__init__(self, domain, text, self.regex) |
|
| 5 | 472 |
|
473 |
||
474 |
class WhoisJp(WhoisEntry): |
|
475 |
"""Whois parser for .jp domains |
|
476 |
""" |
|
477 |
regex = {
|
|
478 |
'domain_name': 'a\. \[Domain Name\]\s*(.+)', |
|
479 |
'registrant_org': 'g\. \[Organization\](.+)', |
|
480 |
'creation_date': r'\[Registered Date\]\s*(.+)', |
|
481 |
'name_servers': 'p\. \[Name Server\]\s*(.+)', # list of name servers |
|
482 |
'updated_date': '\[Last Update\]\s?(.+)', |
|
483 |
'status': '\[State\]\s*(.+)', # list of statuses |
|
484 |
} |
|
485 |
||
486 |
def __init__(self, domain, text): |
|
487 |
if text.strip() == 'No entries found': |
|
488 |
raise PywhoisError(text) |
|
489 |
else: |
|
490 |
WhoisEntry.__init__(self, domain, text, self.regex) |
|
| 15 | 491 |
|
| 17 | 492 |
|
493 |
class WhoisAU(WhoisEntry): |
|
494 |
"""Whois parser for .au domains |
|
495 |
""" |
|
496 |
regex = {
|
|
497 |
'domain_name': 'Domain Name:\s*(.+)\n', |
|
498 |
'last_modified': 'Last Modified:\s*(.+)\n', |
|
499 |
'registrar': 'Registrar Name:\s*(.+)\n', |
|
500 |
'status': 'Status:\s*(.+)', |
|
501 |
'registrant_name': 'Registrant:\s*(.+)', |
|
502 |
'name_servers': 'Name Server:\s*(.+)', |
|
503 |
} |
|
504 |
def __init__(self, domain, text): |
|
505 |
if text.strip() == 'No Data Found': |
|
506 |
raise PywhoisError(text) |
|
507 |
else: |
|
508 |
WhoisEntry.__init__(self, domain, text, self.regex) |
|
509 |
||
510 |
||
| 20 | 511 |
class WhoisEu(WhoisEntry): |
512 |
"""Whois parser for .eu domains |
|
513 |
""" |
|
514 |
regex = {
|
|
515 |
'domain_name': r'Domain:\s*([^\n\r]+)', |
|
516 |
'tech_name': r'Technical:\s*Name:\s*([^\n\r]+)', |
|
517 |
'tech_org': r'Technical:\s*Name:\s*[^\n\r]+\s*Organisation:\s*([^\n\r]+)', |
|
518 |
'tech_phone': r'Technical:\s*Name:\s*[^\n\r]+\s*Organisation:\s*[^\n\r]+\s*Language:\s*[^\n\r]+\s*Phone:\s*([^\n\r]+)', |
|
519 |
'tech_fax': r'Technical:\s*Name:\s*[^\n\r]+\s*Organisation:\s*[^\n\r]+\s*Language:\s*[^\n\r]+\s*Phone:\s*[^\n\r]+\s*Fax:\s*([^\n\r]+)', |
|
520 |
'tech_email': r'Technical:\s*Name:\s*[^\n\r]+\s*Organisation:\s*[^\n\r]+\s*Language:\s*[^\n\r]+\s*Phone:\s*[^\n\r]+\s*Fax:\s*[^\n\r]+\s*Email:\s*([^\n\r]+)', |
|
521 |
'registrar': r'Registrar:\s*Name:\s*([^\n\r]+)', |
|
522 |
'name_servers': r'Name servers:\s*([^\n\r]+)\s*([^\n\r]*)\s*([^\n\r]*)\s*([^\n\r]*)\s*([^\n\r]*)\s*([^\n\r]*)\s*([^\n\r]*)\s*([^\n\r]*)\s*([^\n\r]*)\s*Keys', # list of name servers |
|
523 |
} |
|
524 |
||
525 |
def __init__(self, domain, text): |
|
526 |
if text.strip() == 'Status: AVAILABLE': |
|
527 |
raise PywhoisError(text) |
|
528 |
else: |
|
529 |
WhoisEntry.__init__(self, domain, text, self.regex) |
|
530 |
||
531 |
||
| 15 | 532 |
class WhoisBr(WhoisEntry): |
533 |
"""Whois parser for .br domains |
|
534 |
""" |
|
535 |
regex = {
|
|
536 |
'domain': 'domain:\s*(.+)\n', |
|
537 |
'owner': 'owner:\s*([\S ]+)', |
|
538 |
'ownerid': 'ownerid:\s*(.+)', |
|
539 |
'country': 'country:\s*(.+)', |
|
540 |
'owner_c': 'owner-c:\s*(.+)', |
|
541 |
'admin_c': 'admin-c:\s*(.+)', |
|
542 |
'tech_c': 'tech-c:\s*(.+)', |
|
543 |
'billing_c': 'billing-c:\s*(.+)', |
|
544 |
'nserver': 'nserver:\s*(.+)', |
|
545 |
'nsstat': 'nsstat:\s*(.+)', |
|
546 |
'nslastaa': 'nslastaa:\s*(.+)', |
|
547 |
'saci': 'saci:\s*(.+)', |
|
548 |
'created': 'created:\s*(.+)', |
|
549 |
'expires': 'expires:\s*(.+)', |
|
550 |
'changed': 'changed:\s*(.+)', |
|
551 |
'status': 'status:\s*(.+)', |
|
552 |
'nic_hdl_br': 'nic-hdl-br:\s*(.+)', |
|
553 |
'person': 'person:\s*([\S ]+)', |
|
554 |
'email': 'e-mail:\s*(.+)', |
|
555 |
} |
|
556 |
||
557 |
def __init__(self, domain, text): |
|
558 |
||
559 |
if 'Not found:' in text: |
|
560 |
raise PywhoisError(text) |
|
561 |
else: |
|
562 |
WhoisEntry.__init__(self, domain, text, self.regex) |
|
563 |
||
| 19 | 564 |
|
565 |
class WhoisKr(WhoisEntry): |
|
566 |
"""Whois parser for .kr domains |
|
567 |
""" |
|
568 |
regex = {
|
|
569 |
'domain_name': 'Domain Name\s*:\s*(.+)', |
|
570 |
'registrant_org': 'Registrant\s*:\s*(.+)', |
|
571 |
'registrant_address': 'Registrant Address\s*:\s*(.+)', |
|
572 |
'registrant_zip': 'Registrant Zip Code\s*:\s*(.+)', |
|
573 |
'admin_name': 'Administrative Contact\(AC\)\s*:\s*(.+)', |
|
574 |
'admin_email': 'AC E-Mail\s*:\s*(.+)', |
|
575 |
'admin_phone': 'AC Phone Number\s*:\s*(.+)', |
|
576 |
'creation_date': 'Registered Date\s*:\s*(.+)', |
|
577 |
'updated_date': 'Last updated Date\s*:\s*(.+)', |
|
578 |
'expiration_date': 'Expiration Date\s*:\s*(.+)', |
|
579 |
'registrar': 'Authorized Agency\s*:\s*(.+)', |
|
580 |
'name_servers': 'Host Name\s*:\s*(.+)', # list of name servers |
|
581 |
} |
|
582 |
||
583 |
def __init__(self, domain, text): |
|
584 |
if text.strip() == 'No entries found': |
|
585 |
raise PywhoisError(text) |
|
586 |
else: |
|
587 |
WhoisEntry.__init__(self, domain, text, self.regex) |
|
588 |
||
589 |
||
| 21 | 590 |
class WhoisPt(WhoisEntry): |
591 |
"""Whois parser for .pt domains |
|
592 |
""" |
|
593 |
regex = {
|
|
594 |
'domain_name': 'domain name:\s*(.+)', |
|
595 |
'creation_date': 'creation date \(dd\/mm\/yyyy\):\s*(.+)', |
|
596 |
'expiration_date': 'expiration date \(dd\/mm\/yyyy\):\s*(.+)', |
|
597 |
'name_servers': '\tNS\t(.+).', # list of name servers |
|
598 |
'status': 'status:\s*(.+)', # list of statuses |
|
599 |
'emails': '[\w.-]+@[\w.-]+\.[\w]{2,4}', # list of email addresses
|
|
600 |
} |
|
601 |
||
602 |
def __init__(self, domain, text): |
|
603 |
if text.strip() == 'No entries found': |
|
604 |
raise PywhoisError(text) |
|
605 |
else: |
|
606 |
WhoisEntry.__init__(self, domain, text, self.regex) |
|
|
26
e0b929723473
Add expiry_date regex for .bg domains
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
24
diff
changeset
|
607 |
|
|
e0b929723473
Add expiry_date regex for .bg domains
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
24
diff
changeset
|
608 |
class WhoisBg(WhoisEntry): |
|
e0b929723473
Add expiry_date regex for .bg domains
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
24
diff
changeset
|
609 |
"""Whois parser for .bg domains""" |
|
e0b929723473
Add expiry_date regex for .bg domains
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
24
diff
changeset
|
610 |
|
|
e0b929723473
Add expiry_date regex for .bg domains
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
24
diff
changeset
|
611 |
regex = {
|
|
e0b929723473
Add expiry_date regex for .bg domains
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
24
diff
changeset
|
612 |
'expiration_date': 'expires at:\s*(.+)', |
|
e0b929723473
Add expiry_date regex for .bg domains
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
24
diff
changeset
|
613 |
} |
|
e0b929723473
Add expiry_date regex for .bg domains
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
24
diff
changeset
|
614 |
|
|
e0b929723473
Add expiry_date regex for .bg domains
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
24
diff
changeset
|
615 |
def __init__(self, domain, text): |
|
e0b929723473
Add expiry_date regex for .bg domains
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
24
diff
changeset
|
616 |
if text.strip() == 'No entries found': |
|
e0b929723473
Add expiry_date regex for .bg domains
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
24
diff
changeset
|
617 |
raise PywhoisError(text) |
|
e0b929723473
Add expiry_date regex for .bg domains
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
24
diff
changeset
|
618 |
else: |
|
e0b929723473
Add expiry_date regex for .bg domains
Evgeni Kunev <evgeni.kunev@gmail.com>
parents:
24
diff
changeset
|
619 |
WhoisEntry.__init__(self, domain, text, self.regex) |