Last active
September 30, 2015 10:57
-
-
Save rindeal/5868368a8797637e1137 to your computer and use it in GitHub Desktop.
Script to retrieve info about a dnsmasq instance
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
#!/bin/sh | |
# usage: | |
# - $0 # queries the default server | |
# - $0 NAMESERVER_IP # queries the provided server | |
# ------------------------------------------------------------------------------ | |
# Example output: | |
# dnsmasq : 127.0.1.1 | |
# servers : 8.8.8.8#53 216 1 # template: "IP#port valid_responses invalid_responses" | |
# cachesize : 10000 | |
# insertions: 9876 | |
# hits : 5678 | |
# misses : 1234 | |
# ------------------------------------------------------------------------------ | |
# | |
COL_SZ=10 | |
DIG="$(which dig 2>/dev/null)" | |
[ $? != 0 ] && echo "Command 'dig' not found" && exit 1 | |
if [ -z "$1" ]; then | |
DNS_SERVER="$("$DIG" txt chaos hits.bind | grep -o ";; SERVER: [0-9\.]*" | cut -d" " -f3 )" | |
else | |
DNS_SERVER="$1" | |
fi | |
printf "%-${COL_SZ}s: %s\n" "dnsmasq" "$DNS_SERVER" | |
for name in servers cachesize insertions hits misses;do | |
printf "%-${COL_SZ}s: " "$name" | |
"$DIG" @$DNS_SERVER +short chaos txt $name.bind | tr -d '"' | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment