-
Notifications
You must be signed in to change notification settings - Fork 196
/
Copy pathparser.py
3498 lines (3061 loc) · 145 KB
/
parser.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
# parser.py - Module for parsing whois response data
# Copyright (c) 2008 Andrey Petrov
#
# This module is part of python-whois and is released under
# the MIT license: http://www.opensource.org/licenses/mit-license.php
import json
import re
from datetime import datetime
from typing import Any, Callable, Optional, Union
import dateutil.parser as dp
from dateutil.utils import default_tzinfo
from .exceptions import WhoisDomainNotFoundError, WhoisUnknownDateFormatError
from .time_zones import tz_data
EMAIL_REGEX: str = (
r"[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*["
r"a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?"
)
KNOWN_FORMATS: list[str] = [
"%d-%b-%Y", # 02-jan-2000
"%d-%B-%Y", # 11-February-2000
"%d-%m-%Y", # 20-10-2000
"%Y-%m-%d", # 2000-01-02
"%d.%m.%Y", # 2.1.2000
"%Y.%m.%d", # 2000.01.02
"%Y/%m/%d", # 2000/01/02
"%Y/%m/%d %H:%M:%S", # 2011/06/01 01:05:01
"%Y/%m/%d %H:%M:%S (%z)", # 2011/06/01 01:05:01 (+0900)
"%Y%m%d", # 20170209
"%Y%m%d %H:%M:%S", # 20110908 14:44:51
"%d/%m/%Y", # 02/01/2013
"%Y. %m. %d.", # 2000. 01. 02.
"%Y.%m.%d %H:%M:%S", # 2014.03.08 10:28:24
"%d-%b-%Y %H:%M:%S %Z", # 24-Jul-2009 13:20:03 UTC
"%a %b %d %H:%M:%S %Z %Y", # Tue Jun 21 23:59:59 GMT 2011
"%a %b %d %Y", # Tue Dec 12 2000
"%Y-%m-%dT%H:%M:%S", # 2007-01-26T19:10:31
"%Y-%m-%dT%H:%M:%SZ", # 2007-01-26T19:10:31Z
"%Y-%m-%dT%H:%M:%SZ[%Z]", # 2007-01-26T19:10:31Z[UTC]
"%Y-%m-%d %H:%M:%S.%f", # 2018-05-19 12:18:44.329522
"%Y-%m-%dT%H:%M:%S.%fZ", # 2018-12-01T16:17:30.568Z
"%Y-%m-%dT%H:%M:%S.%f%z", # 2011-09-08T14:44:51.622265+03:00
"%Y-%m-%d %H:%M:%S%z", # 2018-11-02 11:29:08+02:00
"%Y-%m-%dT%H:%M:%S%z", # 2013-12-06T08:17:22-0800
"%Y-%m-%dT%H:%M:%S%zZ", # 1970-01-01T02:00:00+02:00Z
"%Y-%m-%dt%H:%M:%S.%f", # 2011-09-08t14:44:51.622265
"%Y-%m-%dt%H:%M:%S", # 2007-01-26T19:10:31
"%Y-%m-%dt%H:%M:%SZ", # 2007-01-26T19:10:31Z
"%Y-%m-%dt%H:%M:%S.%fz", # 2007-01-26t19:10:31.00z
"%Y-%m-%dt%H:%M:%S%z", # 2011-03-30T19:36:27+0200
"%Y-%m-%dt%H:%M:%S.%f%z", # 2011-09-08T14:44:51.622265+03:00
"%Y-%m-%d %H:%M:%SZ", # 2000-08-22 18:55:20Z
"%Y-%m-%d %H:%M:%S", # 2000-08-22 18:55:20
"%d %b %Y %H:%M:%S", # 08 Apr 2013 05:44:00
"%d/%m/%Y %H:%M:%S", # 23/04/2015 12:00:07 EEST
"%d/%m/%Y %H:%M:%S %Z", # 23/04/2015 12:00:07 EEST
"%d/%m/%Y %H:%M:%S.%f %Z", # 23/04/2015 12:00:07.619546 EEST
"%B %d %Y", # August 14 2017
"%d.%m.%Y %H:%M:%S", # 08.03.2014 10:28:24
"before %Y", # before 2001
"before %b-%Y", # before aug-1996
"before %Y-%m-%d", # before 1996-01-01
"before %Y%m%d", # before 19960821
"%Y-%m-%d %H:%M:%S (%Z%z)", # 2017-09-26 11:38:29 (GMT+00:00)
"%Y-%b-%d.", # 2024-Apr-02.
]
def datetime_parse(s: str) -> Union[str, datetime]:
for known_format in KNOWN_FORMATS:
try:
return datetime.strptime(s, known_format)
except ValueError:
pass # Wrong format, keep trying
raise WhoisUnknownDateFormatError(f"Unknown date format: {s}")
def cast_date(
s: str, dayfirst: bool = False, yearfirst: bool = False
) -> Union[str, datetime]:
"""Convert any date string found in WHOIS to a datetime object."""
try:
# Use datetime.timezone.utc to support < Python3.9
return default_tzinfo(
dp.parse(s, tzinfos=tz_data, dayfirst=dayfirst, yearfirst=yearfirst),
datetime.timezone.utc,
)
except Exception:
return datetime_parse(s)
class WhoisEntry(dict):
"""Base class for parsing a Whois entries."""
# regular expressions to extract domain data from whois profile
# child classes will override this
_regex: dict[str, str] = {
"domain_name": r"Domain Name: *(.+)",
"registrar": r"Registrar: *(.+)",
"registrar_url": r"Registrar URL: *(.+)",
"reseller": r"Reseller: *(.+)",
"whois_server": r"Whois Server: *(.+)",
"referral_url": r"Referral URL: *(.+)", # http url of whois_server
"updated_date": r"Updated Date: *(.+)",
"creation_date": r"Creation Date: *(.+)",
"expiration_date": r"Expir\w+ Date: *(.+)",
"name_servers": r"Name Server: *(.+)", # list of name servers
"status": r"Status: *(.+)", # list of statuses
"emails": EMAIL_REGEX, # list of email s
"dnssec": r"dnssec: *([\S]+)",
"name": r"Registrant Name: *(.+)",
"org": r"Registrant\s*Organization: *(.+)",
"address": r"Registrant Street: *(.+)",
"city": r"Registrant City: *(.+)",
"state": r"Registrant State/Province: *(.+)",
"registrant_postal_code": r"Registrant Postal Code: *(.+)",
"country": r"Registrant Country: *(.+)",
}
# allows for data string manipulation before casting to date
_data_preprocessor: Optional[Callable[[str], str]] = None
dayfirst: bool = False
yearfirst: bool = False
def __init__(self, domain: str, text: str, regex: Optional[dict[str, str]] = None, data_preprocessor: Optional[Callable[[str], str]] = None):
if (
"This TLD has no whois server, but you can access the whois database at"
in text
):
raise WhoisDomainNotFoundError(text)
else:
self.domain = domain
self.text = text
if regex is not None:
self._regex = regex
if data_preprocessor is not None:
self._data_preprocessor = data_preprocessor
self.parse()
def parse(self) -> None:
"""The first time an attribute is called it will be calculated here.
The attribute is then set to be accessed directly by subsequent calls.
"""
for attr, regex in list(self._regex.items()):
if regex:
values: list[Union[str, datetime]] = []
for data in re.findall(regex, self.text, re.IGNORECASE | re.M):
matches = data if isinstance(data, tuple) else [data]
for value in matches:
value = self._preprocess(attr, value)
if value and str(value).lower() not in [
str(v).lower() for v in values
]:
# avoid duplicates
values.append(value)
if values and attr in ("registrar", "whois_server", "referral_url"):
values = values[-1:] # ignore junk
if len(values) == 1:
self[attr] = values[0]
elif values:
self[attr] = values
else:
self[attr] = None
def _preprocess(self, attr: str, value: str) -> Union[str, datetime]:
value = value.strip()
if value and isinstance(value, str) and not value.isdigit() and "_date" in attr:
# try casting to date format
# if data_preprocessor is set, use it to preprocess the data string
if self._data_preprocessor:
value = self._data_preprocessor(value)
return cast_date(value, dayfirst=self.dayfirst, yearfirst=self.yearfirst)
return value
def __setitem__(self, name: str, value: Any) -> None:
super(WhoisEntry, self).__setitem__(name, value)
def __getattr__(self, name: str) -> Any:
return self.get(name)
def __str__(self) -> str:
def handler(e):
return str(e)
return json.dumps(self, indent=2, default=handler, ensure_ascii=False)
def __getstate__(self) -> dict:
return self.__dict__
def __setstate__(self, state: dict) -> None:
self.__dict__ = state
@staticmethod
def load(domain: str, text: str):
"""Given whois output in ``text``, return an instance of ``WhoisEntry``
that represents its parsed contents.
"""
if text.strip() == "No whois server is known for this kind of object.":
raise WhoisDomainNotFoundError(text)
if domain.endswith(".com"):
return WhoisCom(domain, text)
elif domain.endswith(".net"):
return WhoisNet(domain, text)
elif domain.endswith(".org"):
return WhoisOrg(domain, text)
elif domain.endswith(".name"):
return WhoisName(domain, text)
elif domain.endswith(".me"):
return WhoisMe(domain, text)
elif domain.endswith(".ae"):
return WhoisAe(domain, text)
elif domain.endswith(".au"):
return WhoisAU(domain, text)
elif domain.endswith(".ru"):
return WhoisRu(domain, text)
elif domain.endswith(".us"):
return WhoisUs(domain, text)
elif domain.endswith(".uk"):
return WhoisUk(domain, text)
elif domain.endswith(".fr"):
return WhoisFr(domain, text)
elif domain.endswith(".nl"):
return WhoisNl(domain, text)
elif domain.endswith(".lt"):
return WhoisLt(domain, text)
elif domain.endswith(".fi"):
return WhoisFi(domain, text)
elif domain.endswith(".hr"):
return WhoisHr(domain, text)
elif domain.endswith(".hn"):
return WhoisHn(domain, text)
elif domain.endswith(".hk"):
return WhoisHk(domain, text)
elif domain.endswith(".jp"):
return WhoisJp(domain, text)
elif domain.endswith(".pl"):
return WhoisPl(domain, text)
elif domain.endswith(".br"):
return WhoisBr(domain, text)
elif domain.endswith(".eu"):
return WhoisEu(domain, text)
elif domain.endswith(".ee"):
return WhoisEe(domain, text)
elif domain.endswith(".kr"):
return WhoisKr(domain, text)
elif domain.endswith(".pt"):
return WhoisPt(domain, text)
elif domain.endswith(".bg"):
return WhoisBg(domain, text)
elif domain.endswith(".de"):
return WhoisDe(domain, text)
elif domain.endswith(".at"):
return WhoisAt(domain, text)
elif domain.endswith(".ca"):
return WhoisCa(domain, text)
elif domain.endswith(".be"):
return WhoisBe(domain, text)
elif domain.endswith(".рф"):
return WhoisRf(domain, text)
elif domain.endswith(".info"):
return WhoisInfo(domain, text)
elif domain.endswith(".su"):
return WhoisSu(domain, text)
elif domain.endswith(".si"):
return WhoisSi(domain, text)
elif domain.endswith(".kg"):
return WhoisKg(domain, text)
elif domain.endswith(".io"):
return WhoisIo(domain, text)
elif domain.endswith(".biz"):
return WhoisBiz(domain, text)
elif domain.endswith(".mobi"):
return WhoisMobi(domain, text)
elif domain.endswith(".ch"):
return WhoisChLi(domain, text)
elif domain.endswith(".li"):
return WhoisChLi(domain, text)
elif domain.endswith(".id"):
return WhoisID(domain, text)
elif domain.endswith(".sk"):
return WhoisSK(domain, text)
elif domain.endswith(".se"):
return WhoisSe(domain, text)
elif domain.endswith(".no"):
return WhoisNo(domain, text)
elif domain.endswith(".nu"):
return WhoisSe(domain, text)
elif domain.endswith(".is"):
return WhoisIs(domain, text)
elif domain.endswith(".dk"):
return WhoisDk(domain, text)
elif domain.endswith(".it"):
return WhoisIt(domain, text)
elif domain.endswith(".mx"):
return WhoisMx(domain, text)
elif domain.endswith(".ai"):
return WhoisAi(domain, text)
elif domain.endswith(".il"):
return WhoisIl(domain, text)
elif domain.endswith(".in"):
return WhoisIn(domain, text)
elif domain.endswith(".cat"):
return WhoisCat(domain, text)
elif domain.endswith(".ie"):
return WhoisIe(domain, text)
elif domain.endswith(".nz"):
return WhoisNz(domain, text)
elif domain.endswith(".space"):
return WhoisSpace(domain, text)
elif domain.endswith(".lu"):
return WhoisLu(domain, text)
elif domain.endswith(".cz"):
return WhoisCz(domain, text)
elif domain.endswith(".online"):
return WhoisOnline(domain, text)
elif domain.endswith(".cn"):
return WhoisCn(domain, text)
elif domain.endswith(".app"):
return WhoisApp(domain, text)
elif domain.endswith(".money"):
return WhoisMoney(domain, text)
elif domain.endswith(".cl"):
return WhoisCl(domain, text)
elif domain.endswith(".ar"):
return WhoisAr(domain, text)
elif domain.endswith(".by"):
return WhoisBy(domain, text)
elif domain.endswith(".cr"):
return WhoisCr(domain, text)
elif domain.endswith(".do"):
return WhoisDo(domain, text)
elif domain.endswith(".jobs"):
return WhoisJobs(domain, text)
elif domain.endswith(".lat"):
return WhoisLat(domain, text)
elif domain.endswith(".pe"):
return WhoisPe(domain, text)
elif domain.endswith(".ro"):
return WhoisRo(domain, text)
elif domain.endswith(".sa"):
return WhoisSa(domain, text)
elif domain.endswith(".tw"):
return WhoisTw(domain, text)
elif domain.endswith(".tr"):
return WhoisTr(domain, text)
elif domain.endswith(".ve"):
return WhoisVe(domain, text)
elif domain.endswith(".ua"):
if domain.endswith(".pp.ua"):
return WhoisPpUa(domain, text)
return WhoisUA(domain, text)
elif domain.endswith(".укр") or domain.endswith(".xn--j1amh"):
return WhoisUkr(domain, text)
elif domain.endswith(".kz"):
return WhoisKZ(domain, text)
elif domain.endswith(".ir"):
return WhoisIR(domain, text)
elif domain.endswith(".中国"):
return WhoisZhongGuo(domain, text)
elif domain.endswith(".website"):
return WhoisWebsite(domain, text)
elif domain.endswith(".sg"):
return WhoisSG(domain, text)
elif domain.endswith(".ml"):
return WhoisML(domain, text)
elif domain.endswith(".ooo"):
return WhoisOoo(domain, text)
elif domain.endswith(".group"):
return WhoisGroup(domain, text)
elif domain.endswith(".market"):
return WhoisMarket(domain, text)
elif domain.endswith(".za"):
return WhoisZa(domain, text)
elif domain.endswith(".bw"):
return WhoisBw(domain, text)
elif domain.endswith(".bz"):
return WhoisBz(domain, text)
elif domain.endswith(".gg"):
return WhoisGg(domain, text)
elif domain.endswith(".city"):
return WhoisCity(domain, text)
elif domain.endswith(".design"):
return WhoisDesign(domain, text)
elif domain.endswith(".studio"):
return WhoisStudio(domain, text)
elif domain.endswith(".style"):
return WhoisStyle(domain, text)
elif domain.endswith(".рус") or domain.endswith(".xn--p1acf"):
return WhoisPyc(domain, text)
elif domain.endswith(".life"):
return WhoisLife(domain, text)
elif domain.endswith(".tn"):
return WhoisTN(domain, text)
elif domain.endswith(".rs"):
return WhoisRs(domain, text)
elif domain.endswith(".site"):
return WhoisSite(domain, text)
elif domain.endswith(".edu"):
return WhoisEdu(domain, text)
elif domain.endswith(".lv"):
return WhoisLv(domain, text)
elif domain.endswith(".co"):
return WhoisCo(domain, text)
elif domain.endswith(".ga"):
return WhoisGa(domain, text)
else:
return WhoisEntry(domain, text)
class WhoisCl(WhoisEntry):
"""Whois parser for .cl domains"""
regex: dict[str, str] = {
"domain_name": r"Domain name: *(.+)",
"registrant_name": r"Registrant name: *(.+)",
"registrant_organization": r"Registrant organisation: *(.+)",
"registrar": r"registrar name: *(.+)",
"registrar_url": r"Registrar URL: *(.+)",
"creation_date": r"Creation date: *(.+)",
"expiration_date": r"Expiration date: *(.+)",
"name_servers": r"Name server: *(.+)", # list of name servers
}
def __init__(self, domain: str, text: str):
if 'No match for "' in text:
raise WhoisDomainNotFoundError(text)
else:
WhoisEntry.__init__(
self,
domain,
text,
self.regex,
lambda x: x.replace(" CLST", "").replace(" CLT", "")
)
class WhoisSG(WhoisEntry):
"""Whois parser for .sg domains"""
regex: dict[str, str] = {
"domain_name": r"Domain name: *(.+)",
"status": r"Domain Status: *(.+)",
"registrant_name": r"Registrant:\n\s+Name:(.+)",
"registrar": r"Registrar: *(.+)",
"creation_date": r"Creation date: *(.+)",
"updated_date": r"Updated Date: *(.+)",
"expiration_date": r"Registry Expiry Date: *(.+)",
"dnssec": r"DNSSEC: *(.+)",
"name_servers": r"Name server: *(.+)", # list of name servers
}
def __init__(self, domain: str, text: str):
if "Domain Not Found" in text:
raise WhoisDomainNotFoundError(text)
else:
WhoisEntry.__init__(self, domain, text, self.regex)
nsmatch = re.compile("Name Servers:(.*?)DNSSEC:", re.DOTALL).search(text)
if nsmatch:
self["name_servers"] = [
line.strip() for line in nsmatch.groups()[0].strip().splitlines()
]
techmatch = re.compile(
"Technical Contact:(.*?)Name Servers:", re.DOTALL
).search(text)
if techmatch:
for line in techmatch.groups()[0].strip().splitlines():
self[
"technical_contact_" + line.split(":")[0].strip().lower()
] = line.split(":")[1].strip()
class WhoisPe(WhoisEntry):
"""Whois parser for .pe domains"""
regex: dict[str, str] = {
"domain_name": r"Domain name: *(.+)",
"status": r"Domain Status: *(.+)",
"whois_server": r"WHOIS Server: *(.+)",
"registrant_name": r"Registrant name: *(.+)",
"registrar": r"Sponsoring Registrar: *(.+)",
"admin": r"Admin Name: *(.+)",
"admin_email": r"Admin Email: *(.+)",
"dnssec": r"DNSSEC: *(.+)",
"name_servers": r"Name server: *(.+)", # list of name servers
}
def __init__(self, domain: str, text: str):
if 'No match for "' in text:
raise WhoisDomainNotFoundError(text)
else:
WhoisEntry.__init__(self, domain, text, self.regex)
class WhoisSpace(WhoisEntry):
"""Whois parser for .space domains"""
def __init__(self, domain: str, text: str):
if 'No match for "' in text:
raise WhoisDomainNotFoundError(text)
else:
WhoisEntry.__init__(self, domain, text)
class WhoisCom(WhoisEntry):
"""Whois parser for .com domains"""
def __init__(self, domain: str, text: str):
if 'No match for "' in text:
raise WhoisDomainNotFoundError(text)
else:
WhoisEntry.__init__(self, domain, text)
class WhoisNet(WhoisEntry):
"""Whois parser for .net domains"""
def __init__(self, domain: str, text: str):
if 'No match for "' in text:
raise WhoisDomainNotFoundError(text)
else:
WhoisEntry.__init__(self, domain, text)
class WhoisOrg(WhoisEntry):
"""Whois parser for .org domains"""
regex: dict[str, str] = {
"domain_name": r"Domain Name: *(.+)",
"registrar": r"Registrar: *(.+)",
"whois_server": r"Whois Server: *(.+)", # empty usually
"referral_url": r"Referral URL: *(.+)", # http url of whois_server: empty usually
"updated_date": r"Updated Date: *(.+)",
"creation_date": r"Creation Date: *(.+)",
"expiration_date": r"Registry Expiry Date: *(.+)",
"name_servers": r"Name Server: *(.+)", # list of name servers
"status": r"Status: *(.+)", # list of statuses
"emails": EMAIL_REGEX, # list of email addresses
}
def __init__(self, domain: str, text: str):
if text.strip().startswith("NOT FOUND") or text.strip().startswith(
"Domain not found"
):
raise WhoisDomainNotFoundError(text)
else:
WhoisEntry.__init__(self, domain, text)
class WhoisRo(WhoisEntry):
"""Whois parser for .ro domains"""
regex: dict[str, str] = {
"domain_name": r"Domain Name: *(.+)",
"domain_status": r"Domain Status: *(.+)",
"registrar": r"Registrar: *(.+)",
"referral_url": r"Referral URL: *(.+)", # http url of whois_server: empty usually
"creation_date": r"Registered On: *(.+)",
"expiration_date": r"Expires On: *(.+)",
"name_servers": r"Nameserver: *(.+)", # list of name servers
"status": r"Status: *(.+)", # list of statuses
"dnssec": r"DNSSEC: *(.+)",
}
def __init__(self, domain: str, text: str):
if text.strip() == "NOT FOUND":
raise WhoisDomainNotFoundError(text)
else:
WhoisEntry.__init__(self, domain, text, self.regex)
class WhoisRu(WhoisEntry):
"""Whois parser for .ru domains"""
regex: dict[str, str] = {
"domain_name": r"domain: *(.+)",
"registrar": r"registrar: *(.+)",
"creation_date": r"created: *(.+)",
"expiration_date": r"paid-till: *(.+)",
"free_date": r"free-date: *(.+)",
"name_servers": r"nserver: *(.+)", # list of name servers
"status": r"state: *(.+)", # list of statuses
"emails": EMAIL_REGEX, # list of email addresses
"org": r"org: *(.+)",
}
def __init__(self, domain: str, text: str):
if "No entries found" in text:
raise WhoisDomainNotFoundError(text)
else:
WhoisEntry.__init__(self, domain, text, self.regex)
class WhoisNl(WhoisEntry):
"""Whois parser for .nl domains"""
regex: dict[str, str] = {
"domain_name": r"Domain Name: *(.+)",
"expiration_date": r"Date\sout\sof\squarantine:\s*(.+)",
"updated_date": r"Updated\sDate:\s*(.+)",
"creation_date": r"Creation\sDate:\s*(.+)",
"status": r"Status: *(.+)", # list of statuses
"registrar": r"Registrar:\s*(.*\n)",
"registrar_address": r"Registrar:\s*(?:.*\n){1}\s*(.*)",
"registrar_postal_code": r"Registrar:\s*(?:.*\n){2}\s*(\S*)\s(?:.*)",
"registrar_city": r"Registrar:\s*(?:.*\n){2}\s*(?:\S*)\s(.*)",
"registrar_country": r"Registrar:\s*(?:.*\n){3}\s*(.*)",
"dnssec": r"DNSSEC: *(.+)",
}
def __init__(self, domain: str, text: str):
if text.endswith("is free"):
raise WhoisDomainNotFoundError(text)
else:
WhoisEntry.__init__(self, domain, text, self.regex)
match = re.compile(
r"Domain nameservers:(.*?)Record maintained by", re.DOTALL
).search(text)
if match:
duplicate_nameservers_with_ip = [
line.strip() for line in match.groups()[0].strip().splitlines()
]
duplicate_nameservers_without_ip = [
nameserver.split(" ")[0] for nameserver in duplicate_nameservers_with_ip
]
self["name_servers"] = sorted(list(set(duplicate_nameservers_without_ip)))
class WhoisLt(WhoisEntry):
"""Whois parser for .lt domains"""
regex: dict[str, str] = {
"domain_name": r"Domain:\s?(.+)",
"expiration_date": r"Expires:\s?(.+)",
"creation_date": r"Registered:\s?(.+)",
"status": r"\nStatus:\s?(.+)", # list of statuses
}
def __init__(self, domain: str, text: str):
if text.endswith("available"):
raise WhoisDomainNotFoundError(text)
else:
WhoisEntry.__init__(self, domain, text, self.regex)
match = re.compile(
r"Domain nameservers:(.*?)Record maintained by", re.DOTALL
).search(text)
if match:
duplicate_nameservers_with_ip = [
line.strip() for line in match.groups()[0].strip().splitlines()
]
duplicate_nameservers_without_ip = [
nameserver.split(" ")[0] for nameserver in duplicate_nameservers_with_ip
]
self["name_servers"] = sorted(list(set(duplicate_nameservers_without_ip)))
class WhoisName(WhoisEntry):
"""Whois parser for .name domains"""
regex: dict[str, str] = {
"domain_name_id": r"Domain Name ID: *(.+)",
"domain_name": r"Domain Name: *(.+)",
"registrar_id": r"Sponsoring Registrar ID: *(.+)",
"registrar": r"Sponsoring Registrar: *(.+)",
"registrant_id": r"Registrant ID: *(.+)",
"admin_id": r"Admin ID: *(.+)",
"technical_id": r"Tech ID: *(.+)",
"billing_id": r"Billing ID: *(.+)",
"creation_date": r"Created On: *(.+)",
"expiration_date": r"Expires On: *(.+)",
"updated_date": r"Updated On: *(.+)",
"name_server_ids": r"Name Server ID: *(.+)", # list of name server ids
"name_servers": r"Name Server: *(.+)", # list of name servers
"status": r"Domain Status: *(.+)", # list of statuses
}
def __init__(self, domain: str, text: str):
if "No match for " in text:
raise WhoisDomainNotFoundError(text)
else:
WhoisEntry.__init__(self, domain, text, self.regex)
class WhoisUs(WhoisEntry):
"""Whois parser for .us domains"""
regex: dict[str, str] = {
"domain_name": r"Domain Name: *(.+)",
"domain__id": r"Domain ID: *(.+)",
"whois_server": r"Registrar WHOIS Server: *(.+)",
"registrar": r"Registrar: *(.+)",
"registrar_id": r"Registrar IANA ID: *(.+)",
"registrar_url": r"Registrar URL: *(.+)",
"registrar_email": r"Registrar Abuse Contact Email: *(.+)",
"registrar_phone": r"Registrar Abuse Contact Phone: *(.+)",
"status": r"Domain Status: *(.+)", # list of statuses
"registrant_id": r"Registry Registrant ID: *(.+)",
"registrant_name": r"Registrant Name: *(.+)",
"registrant_organization": r"Registrant Organization: *(.+)",
"registrant_street": r"Registrant Street: *(.+)",
"registrant_city": r"Registrant City: *(.+)",
"registrant_state_province": r"Registrant State/Province: *(.+)",
"registrant_postal_code": r"Registrant Postal Code: *(.+)",
"registrant_country": r"Registrant Country: *(.+)",
"registrant_phone": r"Registrant Phone: *(.+)",
"registrant_email": r"Registrant Email: *(.+)",
"registrant_fax": r"Registrant Fax: *(.+)",
"registrant_application_purpose": r"Registrant Application Purpose: *(.+)",
"registrant_nexus_category": r"Registrant Nexus Category: *(.+)",
"admin_id": r"Registry Admin ID: *(.+)",
"admin": r"Admin Name: *(.+)",
"admin_organization": r"Admin Organization: *(.+)",
"admin_street": r"Admin Street: *(.+)",
"admin_city": r"Admin City: *(.+)",
"admin_state_province": r"Admin State/Province: *(.+)",
"admin_postal_code": r"Admin Postal Code: *(.+)",
"admin_country": r"Admin Country: *(.+)",
"admin_phone": r"Admin Phone: *(.+)",
"admin_email": r"Admin Email: *(.+)",
"admin_fax": r"Admin Fax: *(.+)",
"admin_application_purpose": r"Admin Application Purpose: *(.+)",
"admin_nexus_category": r"Admin Nexus Category: *(.+)",
"tech_id": r"Registry Tech ID: *(.+)",
"tech_name": r"Tech Name: *(.+)",
"tech_organization": r"Tech Organization: *(.+)",
"tech_street": r"Tech Street: *(.+)",
"tech_city": r"Tech City: *(.+)",
"tech_state_province": r"Tech State/Province: *(.+)",
"tech_postal_code": r"Tech Postal Code: *(.+)",
"tech_country": r"Tech Country: *(.+)",
"tech_phone": r"Tech Phone: *(.+)",
"tech_email": r"Tech Email: *(.+)",
"tech_fax": r"Tech Fax: *(.+)",
"tech_application_purpose": r"Tech Application Purpose: *(.+)",
"tech_nexus_category": r"Tech Nexus Category: *(.+)",
"name_servers": r"Name Server: *(.+)", # list of name servers
"creation_date": r"Creation Date: *(.+)",
"expiration_date": r"Registry Expiry Date: *(.+)",
"updated_date": r"Updated Date: *(.+)",
}
def __init__(self, domain, text):
if "No Data Found" in text:
raise WhoisDomainNotFoundError(text)
else:
WhoisEntry.__init__(self, domain, text, self.regex)
class WhoisPl(WhoisEntry):
"""Whois parser for .pl domains"""
regex: dict[str, str] = {
"domain_name": r"DOMAIN NAME: *(.+)\n",
"name_servers": r"nameservers:(?:\s+(\S+)\.[^\n]*\n)(?:\s+(\S+)\.[^\n]*\n)?(?:\s+(\S+)\.[^\n]*\n)?(?:\s+(\S+)\.[^\n]*\n)?", # up to 4
"registrar": r"REGISTRAR:\s*(.+)",
"registrar_url": r"URL: *(.+)", # not available
"status": r"Registration status:\n\s*(.+)", # not available
"registrant_name": r"Registrant:\n\s*(.+)", # not available
"creation_date": r"(?<! )created: *(.+)\n",
"expiration_date": r"renewal date: *(.+)",
"updated_date": r"last modified: *(.+)\n",
}
def __init__(self, domain: str, text: str):
if "No information available about domain name" in text:
raise WhoisDomainNotFoundError(text)
else:
WhoisEntry.__init__(self, domain, text, self.regex)
class WhoisGroup(WhoisEntry):
"""Whois parser for .group domains"""
regex: dict[str, str] = {
"domain_name": r"Domain Name: *(.+)",
"domain_id": r"Registry Domain ID:(.+)",
"whois_server": r"Registrar WHOIS Server: *(.+)",
"registrar_url": r"Registrar URL: *(.+)",
"updated_date": r"Updated Date: (.+)",
"creation_date": r"Creation Date: (.+)",
"expiration_date": r"Expir\w+ Date:\s?(.+)",
"registrar": r"Registrar:(.+)",
"status": r"Domain status: *(.+)",
"registrant_name": r"Registrant Name:(.+)",
"name_servers": r"Name Server: *(.+)",
}
def __init__(self, domain: str, text: str):
if "Domain not found" in text:
raise WhoisDomainNotFoundError(text)
else:
WhoisEntry.__init__(self, domain, text, self.regex)
class WhoisCa(WhoisEntry):
"""Whois parser for .ca domains"""
regex: dict[str, str] = {
"domain_name": r"Domain name: *(.+)",
"whois_server": r"Registrar WHOIS Server: *(.+)",
"registrar": r"Registrar: *(.+)",
"registrar_url": r"Registrar URL: *(.+)",
"registrant_name": r"Registrant Name: *(.+)",
"registrant_number": r"Registry Registrant ID: *(.+)",
"admin_name": r"Admin Name: *(.+)",
"status": r"Domain status: *(.+)",
"emails": r"Email: *(.+)",
"updated_date": r"Updated Date: *(.+)",
"creation_date": r"Creation Date: *(.+)",
"expiration_date": r"Expiry Date: *(.+)",
"phone": r"Phone: *(.+)",
"fax": r"Fax: *(.+)",
"dnssec": r"dnssec: *([\S]+)",
"name_servers": r"Name Server: *(.+)",
}
def __init__(self, domain: str, text: str):
if "Domain status: available" in text or "Not found:" in text:
raise WhoisDomainNotFoundError(text)
else:
WhoisEntry.__init__(self, domain, text, self.regex)
class WhoisMe(WhoisEntry):
"""Whois parser for .me domains"""
regex: dict[str, str] = {
"domain_id": r"Registry Domain ID:(.+)",
"domain_name": r"Domain Name:(.+)",
"creation_date": r"Creation Date:(.+)",
"updated_date": r"Updated Date:(.+)",
"expiration_date": r"Registry Expiry Date: (.+)",
"registrar": r"Registrar:(.+)",
"status": r"Domain Status:(.+)", # list of statuses
"registrant_id": r"Registrant ID:(.+)",
"registrant_name": r"Registrant Name:(.+)",
"registrant_org": r"Registrant Organization:(.+)",
"registrant_address": r"Registrant Address:(.+)",
"registrant_address2": r"Registrant Address2:(.+)",
"registrant_address3": r"Registrant Address3:(.+)",
"registrant_city": r"Registrant City:(.+)",
"registrant_state_province": r"Registrant State/Province:(.+)",
"registrant_country": r"Registrant Country/Economy:(.+)",
"registrant_postal_code": r"Registrant Postal Code:(.+)",
"registrant_phone": r"Registrant Phone:(.+)",
"registrant_phone_ext": r"Registrant Phone Ext\.:(.+)",
"registrant_fax": r"Registrant FAX:(.+)",
"registrant_fax_ext": r"Registrant FAX Ext\.:(.+)",
"registrant_email": r"Registrant E-mail:(.+)",
"admin_id": r"Admin ID:(.+)",
"admin_name": r"Admin Name:(.+)",
"admin_org": r"Admin Organization:(.+)",
"admin_address": r"Admin Address:(.+)",
"admin_address2": r"Admin Address2:(.+)",
"admin_address3": r"Admin Address3:(.+)",
"admin_city": r"Admin City:(.+)",
"admin_state_province": r"Admin State/Province:(.+)",
"admin_country": r"Admin Country/Economy:(.+)",
"admin_postal_code": r"Admin Postal Code:(.+)",
"admin_phone": r"Admin Phone:(.+)",
"admin_phone_ext": r"Admin Phone Ext\.:(.+)",
"admin_fax": r"Admin FAX:(.+)",
"admin_fax_ext": r"Admin FAX Ext\.:(.+)",
"admin_email": r"Admin E-mail:(.+)",
"tech_id": r"Tech ID:(.+)",
"tech_name": r"Tech Name:(.+)",
"tech_org": r"Tech Organization:(.+)",
"tech_address": r"Tech Address:(.+)",
"tech_address2": r"Tech Address2:(.+)",
"tech_address3": r"Tech Address3:(.+)",
"tech_city": r"Tech City:(.+)",
"tech_state_province": r"Tech State/Province:(.+)",
"tech_country": r"Tech Country/Economy:(.+)",
"tech_postal_code": r"Tech Postal Code:(.+)",
"tech_phone": r"Tech Phone:(.+)",
"tech_phone_ext": r"Tech Phone Ext\.:(.+)",
"tech_fax": r"Tech FAX:(.+)",
"tech_fax_ext": r"Tech FAX Ext\.:(.+)",
"tech_email": r"Tech E-mail:(.+)",
"name_servers": r"Nameservers:(.+)", # list of name servers
}
def __init__(self, domain: str, text: str):
if "NOT FOUND" in text:
raise WhoisDomainNotFoundError(text)
else:
WhoisEntry.__init__(self, domain, text, self.regex)
class WhoisUk(WhoisEntry):
"""Whois parser for .uk domains"""
regex: dict[str, str] = {
"domain_name": r"Domain name:\s*(.+)",
"registrar": r"Registrar:\s*(.+)",
"registrar_url": r"URL:\s*(.+)",
"status": r"Registration status:\s*(.+)", # list of statuses
"registrant_name": r"Registrant:\s*(.+)",
"registrant_type": r"Registrant type:\s*(.+)",
"registrant_street": r"Registrant\'s address:\s*(?:.*\n){2}\s+(.*)",
"registrant_city": r"Registrant\'s address:\s*(?:.*\n){3}\s+(.*)",
"registrant_country": r"Registrant\'s address:\s*(?:.*\n){5}\s+(.*)",
"creation_date": r"Registered on:\s*(.+)",
"expiration_date": r"Expiry date:\s*(.+)",
"updated_date": r"Last updated:\s*(.+)",
"name_servers": r"([\w.-]+\.(?:[\w-]+\.){1,2}[a-zA-Z]{2,}(?!\s+Relevant|\s+Data))\s+",
}
def __init__(self, domain: str, text: str):
if "No match for " in text:
raise WhoisDomainNotFoundError(text)
else:
WhoisEntry.__init__(self, domain, text, self.regex)
class WhoisFr(WhoisEntry):
"""Whois parser for .fr domains"""
regex: dict[str, str] = {
"domain_name": r"domain: *(.+)",
"registrar": r"registrar: *(.+)",
"creation_date": r"created: *(.+)",
"expiration_date": r"Expir\w+ Date:\s?(.+)",
"name_servers": r"nserver: *(.+)", # list of name servers
"status": r"status: *(.+)", # list of statuses
"emails": EMAIL_REGEX, # list of email addresses
"updated_date": r"last-update: *(.+)",
}
def __init__(self, domain: str, text: str):
if "No entries found" in text:
raise WhoisDomainNotFoundError(text)
else:
WhoisEntry.__init__(self, domain, text, self.regex)
class WhoisFi(WhoisEntry):
"""Whois parser for .fi domains"""
regex: dict[str, str] = {
"domain_name": r"domain\.*: *([\S]+)",
"name": r"Holder\s*name\.*: (.+)",
"address": r"[Holder\w\W]address\.*: (.+)",
"phone": r"Holder[\s\w\W]+phone\.*: (.+)",
"email": r"holder email\.*: *([\S]+)",
"status": r"status\.*: (.+)", # list of statuses
"creation_date": r"created\.*: *([\S]+)",
"updated_date": r"modified\.*: *([\S]+)",
"expiration_date": r"expires\.*: *([\S]+)",
"name_servers": r"nserver\.*: *([\S]+) \[\S+\]", # list of name servers
"name_server_statuses": r"nserver\.*: *([\S]+ \[\S+\])", # list of name servers and statuses
"dnssec": r"dnssec\.*: *([\S]+)",
"registrar": r"Registrar\s*registrar\.*: (.+)",
"registrar_site": r"Registrar[\s\w\W]+www\.*: (.+)",
}
dayfirst = True
def __init__(self, domain: str, text: str):
if "Domain not " in text:
raise WhoisDomainNotFoundError(text)
else:
WhoisEntry.__init__(self, domain, text, self.regex)
class WhoisJp(WhoisEntry):
"""Parser for .jp domains
For testing, try *both* of:
nintendo.jp
nintendo.co.jp
"""
not_found = "No match!!"
regex: dict[str, str] = {
"domain_name": r"^(?:a\. )?\[Domain Name\]\s*(.+)",
"registrant_org": r"^(?:g\. )?\[(?:Organization|Registrant)\](.+)",
# 'creation_date': r'\[(?:Registered Date|Created on)\]\s*(.+)',
"organization_type": r"^(?:l\. )?\[Organization Type\]\s*(.+)$",
"creation_date": r"\[(?:Created on)\]\s*(.+)",
"technical_contact_name": r"^(?:n. )?\[(?:Technical Contact)\]\s*(.+)",
"administrative_contact_name": r"^(?:m. )?(?:\[Administrative Contact\]\s*(.+)|Contact Information:\s+^\[Name\](.*))",
# These don't need the X. at the beginning, I just was too lazy to split the pattern off
"administrative_contact_email": r"^(?:X. )?(?:\[Administrative Contact\]\s*(?:.+)|Contact Information:\s+)(?:^\s*.*\s+)*(?:^\[Email\]\s*(.*))",
"administrative_contact_phone": r"^(?:X. )?(?:\[Administrative Contact\]\s*(?:.+)|Contact Information:\s+)(?:^\s*.*\s+)*(?:^\[Phone\]\s*(.*))",
"administrative_contact_fax": r"^(?:X. )?(?:\[Administrative Contact\]\s*(?:.+)|Contact Information:\s+)(?:^\s*.*\s+)*(?:^\[Fax\]\s*(.*))",