czds- ICANN Centralized Zone Data Service Tool |
git clone git://git.acid.vegas/czds.git |
Log | Files | Refs | Archive | README | LICENSE |
czds (2206B)
1 #!/bin/bash 2 # ICANN API for the Centralized Zones Data Service - developed by acidvegas (https://git.acid.vegas/czds) 3 # Reference: https://czds.icann.org 4 5 # Main program starts here 6 echo "ICANN Zone Data Service Script" 7 8 # Define the current date for data organization 9 now=$(date +"%Y-%m-%d") 10 11 # Define the output directory 12 output="zonefiles/$now" 13 14 # Get username and password (interactive if not set by environment variables) 15 username=${CZDS_USER:-$(read -p "ICANN Username: " user && echo "$user")} 16 password=${CZDS_PASS:-$(read -sp "ICANN Password: " pass && echo "$pass")} 17 18 echo "Authenticating as $username..." 19 20 # Make an authentication request 21 response=$(curl -s -X POST "https://account-api.icann.org/api/authenticate" \ 22 -H "Content-Type: application/json" \ 23 -H "Accept: application/json" \ 24 -d "{\"username\":\"$username\",\"password\":\"$password\"}") 25 26 # Extract and return the access access_token 27 access_token=$(echo "$response" | grep -o '"accessToken":"[^"]*' | cut -d '"' -f 4) 28 29 # Check if authentication was successful 30 [ -z $access_token ] && echo "error: authentication failed" && exit 1 31 32 echo "Authenticated successfully & recieved access_token $access_token" 33 34 # Create output directory 35 mkdir -p $output 36 37 echo "Fetching zone report..." 38 39 # Get your zone report stats from the API 40 curl --progress-bar -o $output/.stats.csv -H "Authorization: Bearer $access_token" https://czds-api.icann.org/czds/requests/report 41 42 echo "Scrubbing report for privacy..." 43 44 # Redact username from report for privacy 45 sed -i 's/$username/nobody@no.name/g' $output/report.csv 46 47 echo "Fetching zone file links..." 48 49 # Get the zone file links from the API 50 zone_links=$(curl -s -H "Authorization: Bearer $access_token" https://czds-api.icann.org/czds/downloads/links | grep -o 'https://[^"]*') 51 52 # Download zone files 53 for url in $zone_links; do 54 tld=$(basename "$url" .zone) 55 56 echo "Downloading $url..." 57 58 # Make the GET request and save the response to a file 59 curl --progress-bar -o $output/$tld.txt.gz -H "Authorization: Bearer $access_token" "$url" 60 61 echo "Downloaded $tld zone file to zonefiles/$tld.txt.gz (extracting...)" 62 63 # Unzip the zone file 64 gunzip $output/$tld.txt.gz 65 done 66 67 echo "All zone files downloaded."