Files
SnarfCode/scripts/test_tech_add_record.py

36 lines
1.1 KiB
Python

import urllib.request
import ssl
import json
import urllib.parse
import sys
sys.stdout.reconfigure(encoding='utf-8')
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
def get_token(host):
url = f"https://{host}/api/user/login?user=admin&pass=snarfnetadmin&includeInfo=true"
with urllib.request.urlopen(urllib.request.Request(url), context=ctx, timeout=8) as resp:
return json.loads(resp.read().decode())['token']
token = get_token("dns1.snarfnet.net")
# Test adding an A record
params = {
"token": token,
"domain": "test.snarfnet.net",
"zone": "snarfnet.net",
"type": "A",
"ipAddress": "140.44.4.11",
"ptr": "true",
"createPtrZone": "true"
}
url = f"https://dns1.snarfnet.net/api/zones/records/add?{urllib.parse.urlencode(params)}"
try:
with urllib.request.urlopen(urllib.request.Request(url), context=ctx, timeout=8) as resp:
print("Add record response:", json.loads(resp.read().decode()))
except urllib.error.HTTPError as e:
print("HTTPError:", e.code, e.read().decode())