mirror of
https://github.com/pi-hole/dnsmasq.git
synced 2025-12-19 10:18:25 +00:00
Log parsing utils in contrib/reverse-dns
This commit is contained in:
committed by
Simon Kelley
parent
0705a7e2d5
commit
47b9ac59c7
29
contrib/reverse-dns/reverse_dns.sh
Normal file
29
contrib/reverse-dns/reverse_dns.sh
Normal file
@@ -0,0 +1,29 @@
|
||||
#!/bin/bash
|
||||
# $Id: reverse_dns.sh 4 2015-02-17 20:14:59Z jo $
|
||||
#
|
||||
# Usage: reverse_dns.sh IP
|
||||
# Uses the dnsmasq query log to lookup the name
|
||||
# that was last queried to return the given IP.
|
||||
#
|
||||
|
||||
IP=$1
|
||||
qmIP=`echo $IP | sed 's#\.#\\.#g'`
|
||||
LOG=/var/log/dnsmasq.log
|
||||
|
||||
IP_regex='^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$'
|
||||
|
||||
if ! [[ $IP =~ $IP_regex ]]; then
|
||||
echo -n $IP
|
||||
exit
|
||||
fi
|
||||
|
||||
NAME=`tac $LOG | \
|
||||
grep " is $IP" | head -1 | \
|
||||
sed "s#.* \([^ ]*\) is $qmIP.*#\1#" `
|
||||
|
||||
if [ -z "$NAME" ]; then
|
||||
echo -n $IP
|
||||
else
|
||||
echo -n $NAME
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user