-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_rdns.sh
executable file
·39 lines (34 loc) · 999 Bytes
/
check_rdns.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/bash
# Check that a given host resolves to an IP and it resovles back to the same thing.
#
HOST=$1
if [[ -z "$HOST" ]] ; then
echo "You need to specify a host" >&2
exit 1
fi
export HOST
if echo $HOST | grep -q -P "\d+\.\d+\.\d+\.\d" ; then
#echo "IP"
rdns=$(getent hosts $HOST | awk '{print $2}')
if [[ "$?" != "0" ]] ; then
echo "Could not find reverse DNS for host $HOST with IP $ip" >&2
exit 1
fi
export rdns
echo "Host $HOST resolves back to $rdns"
else
#echo "Hostname. Forward DNS"
ip=$(getent hosts $HOST | awk '{print $1}')
if [[ "$?" != "0" ]] ; then
echo "Could not find forward DNS for host $HOST" >&2
exit 1
fi
export ip
rdns=$(getent hosts $ip | awk '{print $2}')
if [[ "$?" != "0" ]] ; then
echo "Could not find reverse DNS for host $HOST with IP $ip" >&2
exit 1
fi
export rdns
echo "Host $HOST resolves to IP: $ip which resolves back to $rdns"
fi