feat: add infrastructure diagnostic and monitoring scripts
This commit is contained in:
44
scripts/inspect_technitium_records.py
Normal file
44
scripts/inspect_technitium_records.py
Normal file
@@ -0,0 +1,44 @@
|
||||
import urllib.request
|
||||
import urllib.parse
|
||||
import ssl
|
||||
import json
|
||||
import http.client
|
||||
import sys
|
||||
|
||||
sys.stdout.reconfigure(encoding='utf-8')
|
||||
|
||||
ctx = ssl.create_default_context()
|
||||
ctx.check_hostname = False
|
||||
ctx.verify_mode = ssl.CERT_NONE
|
||||
|
||||
def do_req(ip, host_header, path):
|
||||
conn = http.client.HTTPSConnection(ip, 443, context=ctx, timeout=8)
|
||||
conn.request("GET", path, headers={"Host": host_header})
|
||||
resp = conn.getresponse()
|
||||
data = resp.read().decode('utf-8')
|
||||
conn.close()
|
||||
return json.loads(data)
|
||||
|
||||
def get_token(ip, host_header):
|
||||
path = "/api/user/login?user=admin&pass=snarfnetadmin&includeInfo=true"
|
||||
data = do_req(ip, host_header, path)
|
||||
return data['token']
|
||||
|
||||
for ip, host in [("140.44.4.34", "dns1.snarfnet.net"), ("140.44.4.62", "dns2.snarfnet.net")]:
|
||||
print(f"\n======================================")
|
||||
print(f"Checking {host} ({ip})...")
|
||||
try:
|
||||
token = get_token(ip, host)
|
||||
# Get records in snarfnet.net
|
||||
p = urllib.parse.urlencode({"token": token, "domain": "snarfnet.net", "zone": "snarfnet.net", "listZone": "true"})
|
||||
res = do_req(ip, host, f"/api/zones/records/get?{p}")
|
||||
records = res.get("response", {}).get("records", [])
|
||||
for r in records:
|
||||
name = r.get("name")
|
||||
rtype = r.get("type")
|
||||
rdata = r.get("rData", {})
|
||||
if any(k in name for k in ["pihole", "dns", "ns"]):
|
||||
print(f" {name} ({rtype}) -> {rdata}")
|
||||
except Exception as e:
|
||||
print(f" Error: {e}")
|
||||
|
||||
Reference in New Issue
Block a user