Skip to content
This repository was archived by the owner on Feb 3, 2024. It is now read-only.

Commit 7fd6d6b

Browse files
committed
add a simple pattern analizer for future use
1 parent cbcf552 commit 7fd6d6b

File tree

3 files changed

+90
-29
lines changed

3 files changed

+90
-29
lines changed

DONE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,5 @@ DONE
4343
- convert the list of tld to Dict
4444
- allow override or change and adding new domains without needing a new version directly
4545
- tested with existing testdomains, all reponses will now respond with the true tld not the one with a underscore
46+
47+
- add simple autodetect based on tld from IANA, try to use the .com patterns to se if we get someting usefull

analize_patterns.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#! /usr/bin/env python3
2+
3+
import sys
4+
import re
5+
from typing import (
6+
# Optional,
7+
# List,
8+
Dict,
9+
)
10+
11+
# most likely we can now introduce trailing whitespace trim on all lines from whois,
12+
# and simplefy trailing whitespace rules
13+
# as \r is already gone now and that was the most disticnt line ending
14+
# occasionally we need to detect \n\s+ for groups that belong together
15+
# mostly with indented blocks of nameservers
16+
17+
# import whois
18+
from whois.tld_regexpr import ZZ
19+
20+
21+
def buildRegCollection(zz: Dict):
22+
regCollection = {}
23+
# get all regexes
24+
for name in zz:
25+
# print(name)
26+
z = zz[name]
27+
for key in z:
28+
if key is None:
29+
continue
30+
31+
if key.startswith("_"):
32+
continue
33+
34+
if key in ["extend"]:
35+
continue
36+
37+
if key not in regCollection:
38+
regCollection[key] = {}
39+
40+
reg = z[key]
41+
if reg is None:
42+
continue
43+
44+
regCollection[key][reg] = None
45+
if isinstance(reg, str):
46+
regCollection[key][reg] = re.compile(reg, flags=re.IGNORECASE)
47+
48+
return regCollection
49+
50+
51+
if __name__ == "__main__":
52+
regCollection = buildRegCollection(ZZ)
53+
54+
for name in sorted(regCollection.keys()):
55+
print(f"## {name}", file=sys.stderr)
56+
for key in sorted(regCollection[name].keys()):
57+
if key:
58+
print(f"{name}: {key}")

compare_known_tld.py

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -67,34 +67,35 @@
6767
found = {}
6868
for tld in dataList2:
6969
data, status = i.getInfoOnOneTld(tld)
70-
# print(status, data)
71-
72-
if data and "whois" in data and data["whois"] and data["whois"] != "NULL":
73-
wh = data["whois"]
74-
if wh.endswith(f".{tld}"):
75-
dd = wh.split(".")[-2:]
76-
else:
77-
dd = ["meta", tld]
78-
79-
zz = _do_whois_query(
80-
dd,
81-
ignore_returncode=False,
82-
server=wh,
83-
)
84-
85-
pp = {"_server": wh, "extend": "com"}
86-
aDictToTestOverride = {tld: pp}
87-
88-
whois.mergeExternalDictWithRegex(aDictToTestOverride)
89-
try:
90-
d = whois.query(".".join(dd))
91-
if d:
92-
print(d.__dict__)
93-
if len(d.name_servers) > 0:
94-
found[tld] = pp
95-
print(f"## ZZ['{tld}'] = {found[tld]} # auto-detected via IANA tld")
96-
except Exception as e:
97-
print(e)
9870

71+
xtest = data and ("whois" in data) and (data["whois"]) and (data["whois"] != "NULL")
72+
if not xtest:
73+
print(f"no whois info for tld: {tld} {data}")
74+
continue
75+
76+
wh = data["whois"]
77+
if wh.endswith(f".{tld}"):
78+
dd = wh.split(".")[-2:]
9979
else:
100-
print(f"no whois info for tld: {tld}\n", data)
80+
dd = ["meta", tld]
81+
82+
print(f"try: {tld}")
83+
zz = _do_whois_query(
84+
dd,
85+
ignore_returncode=False,
86+
server=wh,
87+
)
88+
89+
pp = {"_server": wh, "extend": "com"}
90+
aDictToTestOverride = {tld: pp}
91+
92+
whois.mergeExternalDictWithRegex(aDictToTestOverride)
93+
try:
94+
d = whois.query(".".join(dd))
95+
if d:
96+
print(d.__dict__)
97+
if len(d.name_servers) > 0:
98+
found[tld] = pp
99+
print(f"## ZZ['{tld}'] = {found[tld]} # auto-detected via IANA tld")
100+
except Exception as e:
101+
print(e)

0 commit comments

Comments
 (0)