-
Notifications
You must be signed in to change notification settings - Fork 0
/
rbl_check.sh
46 lines (40 loc) · 1.25 KB
/
rbl_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
#!/bin/bash
# Description: This script is used to check zabbix hosts for RBL entries. It iterates over 'rbl.txt' also found on my github.
# Author: Chris Sabo (https://github.com/csabo) / 12.20.2014
# Requirements: bash, dig, create an external check in zabbix (eg:rbl_ip_check[])
domainIndex=0
result=
mx_list=()
ip_list=()
ip_array=()
domain_array=()
current_domain=
rblIterator=0
# Build array of initial dig return
while read -r _ name; do
mx_list+=("$name")
done < <(dig $1 mx +short)
# Build array of IPs returned from dig
while read -r ip; do
ip_list+=("$ip")
done < <(dig "${mx_list[@]}" +short)
# Generate reverseIP array from ip_list
for ip in "${ip_list[@]}"; do
reverse_ip=$(printf '%s\n' "$ip". | tac -s'.')
ip_array+=("$reverse_ip")
done
# Build array of RBLs
while read -r line; do
domain_array+=("$line")
done < /etc/zabbix/externalscripts/rbl.txt
# Iterate over each reversed IP and dig against the provided domain
for p in "${ip_array[@]}"; do
for z in "${domain_array[@]}"; do
var=$p$z
dig $var |grep NOERROR 1>/dev/null && echo ""${ip_list[@]}" Blacklisted by "$z"" && ((rblIterator++))
done
done
# If not present on any blacklist, echo that out
if [[ $rblIterator == 0 ]]; then
echo "Not in any blacklist"
fi