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