-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnmapfilter.sh
executable file
·61 lines (54 loc) · 1.04 KB
/
nmapfilter.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
#!/bin/bash
if [[ $# == 0 || $1 == "-h" ]]
then
echo "Usage: $0 [-f FIELD] [-p PORT] [-s STATE] [-t SERVICE] FILE...
Filter Nmap output in FILE... based on some parameters.
-f FIELD field numbers, separated by commas and dashes, default to \"1-\"
-p PORT port, in regex, default to \"[0-9]+\"
-s STATE state, default to \".*\"
-t SERVICE service type, default to \".*\"
FILE... input files
"
exit 1
fi
FIELDS=1-
PORT="[0-9]+"
STATE="[^ ]*"
SERVICE="[^ ]*"
while [[ $# > 0 ]]
do
key="$1"
value="$2"
case $key in
-f)
FIELDS="$value"
shift
;;
-p)
PORT="$value"
shift
;;
-s)
STATE="$value"
shift
;;
-t)
SERVICE="$value"
shift
;;
*)
INFILES[${#INFILES[@]}]="$key"
;;
esac
shift
done
cat "${INFILES[@]}" | awk '
/^Nmap scan report for/ {
if (!$6) IP = $5; else IP = substr($6,2,length($6)-2)
}
/^'"$PORT"'\/(tcp|udp) +'"$STATE"' +'"$SERVICE"'/ {
sub("/", " ")
print IP "\t" $1 "\t" $2 "\t" $3 "\t" $4
}
' | cut -f "$FIELDS" | sort --unique
#fikr4n 2015