-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbanip.bak
executable file
·57 lines (57 loc) · 1.84 KB
/
banip.bak
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
#!/bin/bash
read -p 'IP to look for: ' ip
if [[ $ip =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]
then
echo This is a valid ip, $ip
else
echo This is not an IP address
exit 1
fi
if grep -Fq $ip addrules
then
echo IP already exist in addrules
# iptables -L -n |grep $ip
rules=`iptables-save |grep $ip`
echo The current matching rules is this: $rules
echo
# head -15 addrules
# num=`iptables -L -n |wc -l`
# echo There are $num of rules in iptables
var=`cat addrules|wc -l`
var1=7
# echo There are $((var-var1)) active rules in the firewall
count=`cat count`
# echo $count
last=`cat last`
# echo $last
echo There are $((last - $count)) new rules added since the last sort!
echo These are all the new rules added since last sort
awk 'NR >= '$count' && NR <= '$last'' addrules
# code if found
else
echo This is a valid IP address $ip,
echo But it does not exist in the firewall yet, it needs to be added to addrules
echo Adding this ip to addrules and processing updates
sed -i "/^iptables -A INPUT -j LOG/a iptables -A INPUT -s $ip/32 -p tcp -j DROP" addrules
./addrules
rule=`iptables -L -n |grep $ip`
echo The new rule is now active as $rule
# head -15 addrules
# num=`iptables -L -n |wc -l`
# echo There are $num of rules in iptables
var=`cat addrules|wc -l`
var1=7
echo There are $((var-var1)) active rules in the firewall
count=`cat count`
# echo $count
last=`cat last`
echo $((last+1)) >last
last = `cat last`
# echo $last
echo There are $((last - $count)) new rules added since the last sort!
echo These are all the new rules added since last sort
awk 'NR >= '$count' && NR <= '$last'' addrules
# echo Updated last count to $last
# code if not found
fi
echo done