forked from al-caughey/YAMon-v4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clear-iptables.sh
76 lines (69 loc) · 1.8 KB
/
clear-iptables.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
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/sh
##########################################################################
# Yet Another Monitor (YAMon)
# Copyright (c) 2013-present Al Caughey
# All rights reserved.
#
# clears YAMon entries from iptables & ip6tables
# run: manually
# History
# 2020-01-26: 4.0.7 - no changes
# 2020-01-03: 4.0.6 - no changes
# 2019-12-23: 4.0.5 - no changes
# 2019-11-24: 4.0.4 - no changes (yet)
# 2019-06-18: development starts on initial v4 release
#
##########################################################################
function ClearTables(){
cmd="$1"
tables="FORWARD,INPUT,OUTPUT"
echo " > Clearing tables:"
IFS=$','
for tt in $tables
do
oe=$($cmd -nL "$tt" --line-numbers | grep "$str")
[ -z "$oe" ] && echo " * Nothing to clear in $tt" && continue
rn=$(echo "$oe" | awk '{ print $2 }')
echo " * Deleting $rn from $tt"
dup_num=$(echo "$oe" | awk '{ print $1 }')
[ -n "$rn" ] && eval $cmd -D "$tt" $dup_num
done
}
function FlushChains(){
cmd="$1"
echo -e "\n > Flushing chains in $cmd:"
chainlist=$($cmd -L | grep $str | grep Chain)
[ -z "$chainlist" ] && echo " * Nothing to flush" && return
IFS=$'\n'
for ch in $chainlist
do
wc=$(echo $ch | cut -d' ' -f2)
echo " * $wc"
$cmd -F "$wc"
done
}
function DeleteChains(){
cmd="$1"
echo -e "\n > Deleting chains in $cmd:"
chainlist=$($cmd -L | grep $str | grep Chain)
[ -z "$chainlist" ] && echo " * Nothing to flush" && return
IFS=$'\n'
for ch in $chainlist
do
wc=$(echo $ch | cut -d' ' -f2)
echo " * $wc"
$cmd -X "$wc"
done
}
str='YAMONv40'
commands='iptables,ip6tables'
IFS=$','
for c in $commands
do
echo -e "\n*******************\nCleaning entries for $c:"
ClearTables $c
FlushChains $c
DeleteChains $c
IFS=$','
done
echo -e "\n*******************\nAll '$str' entries have been removed from iptables & ip6tables\n\n"