-
Notifications
You must be signed in to change notification settings - Fork 0
/
ipt_analysis
executable file
·89 lines (76 loc) · 1.54 KB
/
ipt_analysis
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
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/bash
##########################
# ipt_analysis will simplify the iptables log reading.
#
# If ipt_analysis doesn't take arguments, it will
# analyse the current day. Otherwise, it will analyse the day
# gave with the -d option.
#
# Contact : [email protected]
###########################
####
# Global variable
DIRSTOR="/usr/local/iptreport"
FREPORT="ipt_report`date '+%d%m%Y%H%M'`"
ANLOG="anlog.awk"
IPTLOG="/var/log/iptables.log"
####
# Function
error() {
echo $* >&2
exit 1
}
syntax() {
echo "Usage : ${0##*/} [-d <day>]"
echo "<day> is 1 day of the month. "
echo "Eg: 12 will be the 12th day of the month"
}
#############################################################################
################ STARTING PROGRAM
if [ ! `id -u` -eq 0 ]
then
error "You must be root to run iptables rules"
fi
test -d $DIRSTOR || mkdir $DIRSTOR
#if [[ $# -gt 2 || $# -eq 1 ]]; then
# syntax
# exit 1
#if [[ $# -ge 1 && $1 != -[a-z] ]]; then
# syntax
# exit 1
#fi
while getopts ":hd:" option
do
case "$option" in
## help option
h)
syntax
exit 0
;;
## day option
d)
nbday=$OPTARG
;;
:)
error "Need an argument for -$OPTARG"
syntax
;;
\?)
error "INVALID OPTION"
syntax
;;
esac
done
if test $nbday; then
if `echo $nbday |egrep -q "^[0-9]{1,}$"`; then
if [[ $nbday -lt 1 || $nbday -gt 31 ]];then
error "<day> out of interval"
fi
awk -f $ANLOG $nbday $DIRSTOR/$FREPORT $IPTLOG
else
error "Syntax error for the <day> argument"
fi
else
awk -f $ANLOG $DIRSTOR/$FREPORT $IPTLOG
fi
exit 0