-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-banip
44 lines (44 loc) · 1.34 KB
/
test-banip
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
read -p 'IP to look for: ' ip
# echo var is $ip
if grep -Fq $ip addrules
then
echo IP already exist in addrules
iptables -L -n |grep $ip
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
# code if found
else
echo Does not exist, 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
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
echo this many new rules are added since last worting
count=`cat count`
echo $count
one=1
incre=$((one+count))
echo There have been $count new rules added since the last sorting
newfw=`head -$incre addrules`
echo Here are the rules,
echo $newfw
newcount = $incre
echo `cat $newcount` > count
echo new count is $count
# code if not found
fi
echo done