-
Notifications
You must be signed in to change notification settings - Fork 1
/
massblackhole_danger.sh
44 lines (34 loc) · 1.01 KB
/
massblackhole_danger.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
#!/bin/bash
# Check if iptables is installed
if ! command -v iptables &> /dev/null; then
echo "Error: iptables is not installed. Please install iptables."
exit 1
fi
# Function to get IP ranges for a given ASN
get_ip_ranges() {
asn="$1"
whois -h whois.radb.net -- "-i origin $asn" | grep -Eo "([0-9.]+){4}/[0-9]+"
}
# Function to drop IP ranges using iptables
drop_ip_ranges() {
while IFS= read -r ip_range; do
sudo iptables -A INPUT -s "$ip_range" -j DROP
echo "Dropped IP range: $ip_range"
done
}
# Main script
input_file="bad_asn.txt"
# Check if the input file exists
if [ ! -f "$input_file" ]; then
echo "Error: File $input_file not found."
exit 1
fi
# Loop through each ASN in the file
while IFS= read -r asn; do
echo "Processing ASN: $asn"
# Get IP ranges for the current ASN
ip_ranges=$(get_ip_ranges "$asn")
# Drop the IP ranges using iptables
echo "$ip_ranges" | drop_ip_ranges
done < "$input_file"
echo "Ultimate Blackhole script completed."