-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathScript to Block any IP.sh
63 lines (48 loc) · 1.54 KB
/
Script to Block any IP.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
#!/bin/bash
### Block all traffic from -----> Use ISO code ###
ISO="cn"
### Set PATH ###
IPT=/sbin/iptables
wget -nv http://www.ipdeny.com/ipblocks/data/countries/all-zones.tar.gz
tar -zxvf all-zones.tar.gz
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -I PREROUTING 1 -j LOG
iptables -t nat -I POSTROUTING 1 -j LOG
iptables -t nat -I OUTPUT 1 -j LOG
cleanOldRules(){
$IPT -F
$IPT -X
$IPT -t nat -F
$IPT -t nat -X
$IPT -t mangle -F
$IPT -t mangle -X
$IPT -P INPUT ACCEPT
$IPT -P OUTPUT ACCEPT
$IPT -P FORWARD ACCEPT
}
# clean old rules
cleanOldRules
for c in $ISO
do
for x in $(cat $c.zone)
do
prips $x >> tmp.txt 2>&1
echo "DEBUG:" $x "extracting ... then onto the next"
#iptables -A INPUT -s $x -j DROP
done
done
echo "Fin"
echo "Onto the next bit, Setting up NAT in IPTables"
cat tmp.txt | while read LINE
do
#echo "DEBUG:Creating IP Table Rule :- iptables -A INPUT -s" $LINE "-j DROP"
#iptables -A INPUT -s $LINE -j DROP LOG --log-prefix "iptables Denied by JAMIE_SCRIPT: " --log-level 7
echo "DEBUG: Dropping and Logging" $LINE
iptables -A INPUT -s $LINE -j LOG --log-prefix "STOP_d: " --log-level 7
iptables -A INPUT -s $LINE -j DROP
#echo "DEBUG:iptables -t nat -A OUTPUT -d" $LINE "-j DNAT --to-destination" $LINE
#iptables -t nat -A OUTPUT -d $LINE -j DNAT --to-destination $LINE
done
echo "Done, Housekeeping..."
rm *.zone
http://tgtechnotes.blogspot.co.uk/