From eb81c1306cc09de29562bbb83ee5bbb476df4ae8 Mon Sep 17 00:00:00 2001 From: Joachim Desroches Date: Thu, 20 Oct 2022 11:48:20 +0200 Subject: [PATCH] Add script to check powerdns records. --- check-dns.sh | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100755 check-dns.sh diff --git a/check-dns.sh b/check-dns.sh new file mode 100755 index 0000000..c023985 --- /dev/null +++ b/check-dns.sh @@ -0,0 +1,34 @@ +#!/bin/sh +# Script to download a list of records setup in PowerDNS and ping the linked A +# and AAAA addresses, printing out those that do not answer. This allows to +# find and clean legacy records. Written by sparrowhawk at work, anno domini +# 2022. + +FILE=rc-records.txt + + +ssh pdns.lnth.ch.recycled.cloud 'pdnsutil list-all-zones | while read -r zone; do pdnsutil list-zone $zone; done' >$FILE + +echo "IPv4:" +awk '/.*\sA\s.*/ { print $1, $5 }' $FILE | sort | while read -r record; +do + host=$(echo "$record" | cut -f1 -d' ') + addr=$(echo "$record" | cut -f2 -d' ') + + if ! ping -c1 "$addr" >/dev/null; + then + echo "$host INEXISTANT" + fi +done + +echo "IPv6:" +awk '/.*\sAAAA\s.*/ { print $1, $5 }' $FILE | sort | while read -r record; +do + host=$(echo "$record" | cut -f1 -d' ') + addr=$(echo "$record" | cut -f2 -d' ') + + if ! ping -c1 "$addr" >/dev/null; + then + echo "$host INEXISTANT" + fi +done