Skip to content

Instantly share code, notes, and snippets.

@stepbrobd
Created July 9, 2024 03:06
Show Gist options
  • Save stepbrobd/7371bcff40535f3430312401d6b1c9d9 to your computer and use it in GitHub Desktop.
Save stepbrobd/7371bcff40535f3430312401d6b1c9d9 to your computer and use it in GitHub Desktop.
icann czds downloader
import argparse
import csv
import gzip
import urllib.request
def main() -> None:
parser = argparse.ArgumentParser()
parser.add_argument("file", type=argparse.FileType("r"))
parser.add_argument("auth", type=str)
args = parser.parse_args()
tlds = []
reader = csv.reader(args.file)
for row in reader:
if row[2] == "approved":
tlds.append(row[1])
for tld in tlds:
print(f"Downloading {tld}.zone")
url = f"https://czds-api.icann.org/czds/downloads/{tld}.zone"
req = urllib.request.Request(url)
req.add_header("Authorization", "Bearer " + args.auth)
with urllib.request.urlopen(req) as response:
with open(f"./zones/{tld}.zone", "wb") as f:
f.write(gzip.decompress(response.read()))
if __name__ == "__main__":
raise SystemExit(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment