]>
Commit | Line | Data |
---|---|---|
47b9ac59 JZ |
1 | #!/bin/bash |
2 | # $Id: reverse_dns.sh 4 2015-02-17 20:14:59Z jo $ | |
3 | # | |
4 | # Usage: reverse_dns.sh IP | |
5 | # Uses the dnsmasq query log to lookup the name | |
6 | # that was last queried to return the given IP. | |
7 | # | |
8 | ||
9 | IP=$1 | |
10 | qmIP=`echo $IP | sed 's#\.#\\.#g'` | |
11 | LOG=/var/log/dnsmasq.log | |
12 | ||
13 | IP_regex='^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$' | |
14 | ||
15 | if ! [[ $IP =~ $IP_regex ]]; then | |
16 | echo -n $IP | |
17 | exit | |
18 | fi | |
19 | ||
20 | NAME=`tac $LOG | \ | |
21 | grep " is $IP" | head -1 | \ | |
22 | sed "s#.* \([^ ]*\) is $qmIP.*#\1#" ` | |
23 | ||
24 | if [ -z "$NAME" ]; then | |
25 | echo -n $IP | |
26 | else | |
27 | echo -n $NAME | |
28 | fi | |
29 |