Created
May 3, 2023 01:06
-
-
Save chrisgrande/b1b9a6b8624b3f96adc2f0b9045c9411 to your computer and use it in GitHub Desktop.
Exports DNS Zone information from your Hover.com account for each domain
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import json | |
# Username and password | |
name = 'username' | |
password = 'password' | |
# Login to Hover | |
s = requests.Session() | |
r = s.post('https://www.hover.com/api/login', | |
data={'username': name, 'password': password}) | |
# Check response | |
r.raise_for_status() | |
# Get json | |
response = s.get('https://www.hover.com/api/dns') | |
# Parse json | |
json_response = json.loads(response.text) | |
# For each domain, create a file with the zone information | |
for i in json_response['domains']: | |
domain_name = i["domain_name"] | |
file_name = f"{domain_name}.txt" | |
with open(file_name, "w") as f: | |
f.write(f'$ORIGIN {domain_name}.\n') | |
types = {} | |
for e in i['entries']: | |
if e["type"] not in types: | |
types[e["type"]] = [] | |
types[e["type"]].append(e) | |
for type_name, entries in types.items(): | |
f.write(f"\n;; {type_name} records\n\n") | |
for e in entries: | |
name = e["name"] if e["name"] != "@" else "" | |
content = e["content"] if e["type"] not in ["TXT"] else f'"{e["content"]}"' | |
if e["type"] in ["CNAME", "DNAME", "MX", "NS", "PTR", "SRV"]: | |
if not content.endswith("."): | |
content += "." | |
ttl = e["ttl"] if "ttl" in e else "" | |
f.write(f'{name}\t{ttl}\tIN\t{e["type"]}\t{content}\n') | |
print(f"{file_name} created successfully!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment