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

Commit

Permalink
add a simple pattern analizer for future use
Browse files Browse the repository at this point in the history
  • Loading branch information
rl-devops committed Jan 27, 2023
1 parent cbcf552 commit 7fd6d6b
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 29 deletions.
2 changes: 2 additions & 0 deletions DONE
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,5 @@ DONE
- convert the list of tld to Dict
- allow override or change and adding new domains without needing a new version directly
- tested with existing testdomains, all reponses will now respond with the true tld not the one with a underscore

- add simple autodetect based on tld from IANA, try to use the .com patterns to se if we get someting usefull
58 changes: 58 additions & 0 deletions analize_patterns.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#! /usr/bin/env python3

import sys
import re
from typing import (
# Optional,
# List,
Dict,
)

# most likely we can now introduce trailing whitespace trim on all lines from whois,
# and simplefy trailing whitespace rules
# as \r is already gone now and that was the most disticnt line ending
# occasionally we need to detect \n\s+ for groups that belong together
# mostly with indented blocks of nameservers

# import whois
from whois.tld_regexpr import ZZ


def buildRegCollection(zz: Dict):
regCollection = {}
# get all regexes
for name in zz:
# print(name)
z = zz[name]
for key in z:
if key is None:
continue

if key.startswith("_"):
continue

if key in ["extend"]:
continue

if key not in regCollection:
regCollection[key] = {}

reg = z[key]
if reg is None:
continue

regCollection[key][reg] = None
if isinstance(reg, str):
regCollection[key][reg] = re.compile(reg, flags=re.IGNORECASE)

return regCollection


if __name__ == "__main__":
regCollection = buildRegCollection(ZZ)

for name in sorted(regCollection.keys()):
print(f"## {name}", file=sys.stderr)
for key in sorted(regCollection[name].keys()):
if key:
print(f"{name}: {key}")
59 changes: 30 additions & 29 deletions compare_known_tld.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,34 +67,35 @@
found = {}
for tld in dataList2:
data, status = i.getInfoOnOneTld(tld)
# print(status, data)

if data and "whois" in data and data["whois"] and data["whois"] != "NULL":
wh = data["whois"]
if wh.endswith(f".{tld}"):
dd = wh.split(".")[-2:]
else:
dd = ["meta", tld]

zz = _do_whois_query(
dd,
ignore_returncode=False,
server=wh,
)

pp = {"_server": wh, "extend": "com"}
aDictToTestOverride = {tld: pp}

whois.mergeExternalDictWithRegex(aDictToTestOverride)
try:
d = whois.query(".".join(dd))
if d:
print(d.__dict__)
if len(d.name_servers) > 0:
found[tld] = pp
print(f"## ZZ['{tld}'] = {found[tld]} # auto-detected via IANA tld")
except Exception as e:
print(e)

xtest = data and ("whois" in data) and (data["whois"]) and (data["whois"] != "NULL")
if not xtest:
print(f"no whois info for tld: {tld} {data}")
continue

wh = data["whois"]
if wh.endswith(f".{tld}"):
dd = wh.split(".")[-2:]
else:
print(f"no whois info for tld: {tld}\n", data)
dd = ["meta", tld]

print(f"try: {tld}")
zz = _do_whois_query(
dd,
ignore_returncode=False,
server=wh,
)

pp = {"_server": wh, "extend": "com"}
aDictToTestOverride = {tld: pp}

whois.mergeExternalDictWithRegex(aDictToTestOverride)
try:
d = whois.query(".".join(dd))
if d:
print(d.__dict__)
if len(d.name_servers) > 0:
found[tld] = pp
print(f"## ZZ['{tld}'] = {found[tld]} # auto-detected via IANA tld")
except Exception as e:
print(e)

0 comments on commit 7fd6d6b

Please sign in to comment.