-
Notifications
You must be signed in to change notification settings - Fork 0
/
dnsbl-check.sh
80 lines (67 loc) · 1.54 KB
/
dnsbl-check.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/bash
# IPs or hostnames to check if none provided as arguments to the script
hosts='
example.com
example.net
example.org
192.0.43.10
'
# Locally maintained list of DNSBLs to check
LocalList='
b.barracudacentral.org
'
# pipe delimited exclude list for remote lists
Exclude='^dnsbl.mailer.mobi$|^foo.bar$|^bar.baz$'
# Remotely maintained list of DNSBLs to check
WPurl="https://en.wikipedia.org/wiki/Comparison_of_DNS_blacklists"
WPlst=$(curl -s $WPurl | egrep "([a-z]+\.){1,7}[a-z]+" | sed -r 's|||g;/$Exclude/d')
# ---------------------------------------------------------------------
HostToIP()
{
if ( echo "$host" | egrep -q "[a-zA-Z]" ); then
IP=$(host "$host" | awk '/[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/ {print$NF}')
else
IP="$host"
fi
}
Repeat()
{
printf "%${2}s\n" | sed "s/ /${1}/g"
}
Reverse()
{
echo $1 | awk -F. '{print$4"."$3"."$2"."$1}'
}
Check()
{
result=$(dig +short $rIP.$BL)
if [ -n "$result" ]; then
echo -e "MAY BE LISTED \t $BL (answer = $result)"
else
echo -e "NOT LISTED \t $BL"
fi
}
if [ -n "$1" ]; then
hosts=$@
fi
if [ -z "$hosts" ]; then
hosts=$(netstat -tn | awk '$4 ~ /[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/ && $4 !~ /127.0.0/ {gsub(/:[0-9]+/,"",$4);} END{print$4}')
fi
for host in $hosts; do
HostToIP
rIP=$(Reverse $IP)
# remote list
echo; Repeat - 100
echo " checking $IP against BLs from $WPurl"
Repeat - 100
for BL in $WPlst; do
Check
done
# local list
echo; Repeat - 100
echo " checking $IP against BLs from a local list"
Repeat - 100
for BL in $LocalList; do
Check
done
done