-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathrblcheck.sh
More file actions
58 lines (47 loc) · 1.68 KB
/
rblcheck.sh
File metadata and controls
58 lines (47 loc) · 1.68 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/sh
# Usage: rblcheck [IP ... ]
# FIXME: If there is a network outage, this script says "not listed" for pretty much everything
IPS="$*"
[ "$IPS" ] || IPS=$( ip addr ls | sed '/ inet \(127\.\|192\.168\.\|10\.\)/ d ; / inet / { s:.* inet :: ; s:/.*:: ; p } ; d ' )
MYIP=$( /sbin/ip route get 8.8.8.8 | sed '/src/ { s/.* src //; s/ .*//;p } ; d')
BLACKLISTS="
cbl.abuseat.org
spam.dnsbl.sorbs.net
"
if tty -s ; then
RED=`tput setaf 1`
GREEN=`tput setaf 2`
RESET=`tput sgr0`
else
RED=
GREEN=
RESET=
fi
for IP in $IPS ; do
# Reverse digits in IP address for lookup ...
REVERSEDIP=$(echo $IP |
sed -ne "s~^\([0-9]\{1,3\}\)\.\([0-9]\{1,3\}\)\.\([0-9]\{1,3\}\)\.\([0-9]\{1,3\}\)$~\4.\3.\2.\1~p"
)
# -- do a REVERSEDIP ( address -> name) DNS lookup
REVERSE_DNS=$(dig +short -x $IP)
if [ "$IP" = "$MYIP" ] ; then
PRIMARY="(Primary IP) "
else
PRIMARY=""
fi
echo "rblcheck $IP $PRIMARY# on `hostname` at $(date '+%Y-%m-%d %H:%M:%S') "
# -- cycle through all the blacklists
for BLACKLIST in ${BLACKLISTS} ; do
#print the query date and time
#show the reversed IP and append the name of the blacklist
#printf "%-40s" " ${REVERSEDIP}.${BLACKLIST}."
# use dig to lookup the name in the blacklist
#echo "$(dig +short -t a ${REVERSEDIP}.${BLACKLIST}. | tr '\n' ' ')"
if dig +short -t a $REVERSEDIP.$BLACKLIST | grep -q ^127\. ; then
LISTED="${RED}LISTED: $(dig +short -t txt $REVERSEDIP.$BLACKLIST )${RESET}"
else
LISTED="${GREEN}not listed${RESET}"
fi
printf " %-16s %-25s %s\\n" "$IP" "$BLACKLIST" "$LISTED"
done
done