Created
October 11, 2021 17:50
-
-
Save dustinbutterworth/b61513df9d8791ac1c9aaff3318f84c6 to your computer and use it in GitHub Desktop.
Check for dangling DNS in a list of CNAMES and their target record
This file contains hidden or 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
| #!/usr/bin/env bash | |
| # FILE is a csv dumped from some source, i.e. Azure. Columns formatted like: "DnsRecord","Record","RecordType" | |
| FILE="AllAzureDnsRecords10-08-2021-16.csv" | |
| NEWFILE="dangling_records.csv" | |
| DEADDNS=() | |
| for line in $(grep "CNAME" ${FILE}); do | |
| TARGET=$(echo ${line} | cut -d, -f2 | sed s/\"//g) | |
| CNAME=$(echo ${line} | cut -d, -f1 | sed s/\"//g) | |
| echo "Checking ${TARGET}..." | |
| RESPONSE=$(host ${TARGET}) | |
| RESULT=$? | |
| if [[ ${RESPONSE} == *"not found"* ]]; then | |
| DEADDNS+=(${CNAME}","${TARGET}) | |
| echo ${RESPONSE} | |
| elif [ ${RESULT} == 1 ]; then | |
| DEADDNS+=(${CNAME}",NULL") | |
| fi | |
| done | |
| echo "CNAME,DEADEND" > ${NEWFILE} | |
| for i in ${DEADDNS[@]}; do | |
| echo ${i} >> ${NEWFILE} | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment