|
@@ -3,11 +3,11 @@ HOSTS_FILES="$HOME/.hosts_scanner"
|
3
|
3
|
#HOSTS_FILES="/tmp/hosts"
|
4
|
4
|
verbose=0
|
5
|
5
|
res_file=$(mktemp -t hosts_scanner.XXXXXXXXXX)
|
6
|
|
-pids=""
|
7
|
6
|
date_cmd="date --rfc-3339=s"
|
8
|
7
|
|
9
|
8
|
lock="${res_file}.lock"
|
10
|
9
|
|
|
10
|
+pids=""
|
11
|
11
|
clean_exit() {
|
12
|
12
|
echo "Ctrl+C pressed, exiting..."
|
13
|
13
|
for pid in $(echo $pids)
|
|
@@ -20,6 +20,17 @@ clean_exit() {
|
20
|
20
|
exit 0
|
21
|
21
|
}
|
22
|
22
|
|
|
23
|
+cidr_pids=""
|
|
24
|
+clean_cidr() {
|
|
25
|
+ echo "CIDR killed, cleaning..."
|
|
26
|
+ for pid in $(echo $cidr_pids)
|
|
27
|
+ do
|
|
28
|
+ kill $pid
|
|
29
|
+ echo $pid killed
|
|
30
|
+ done
|
|
31
|
+ exit 0
|
|
32
|
+}
|
|
33
|
+
|
23
|
34
|
semlock() {
|
24
|
35
|
while [ 1 ]
|
25
|
36
|
do
|
|
@@ -68,14 +79,48 @@ upd_ping() {
|
68
|
79
|
done
|
69
|
80
|
}
|
70
|
81
|
|
|
82
|
+cidr_scan() {
|
|
83
|
+ # cidr ping scan
|
|
84
|
+ # $1 cidr
|
|
85
|
+ # $2 result file
|
|
86
|
+ # $3 lock
|
|
87
|
+
|
|
88
|
+ trap clean_cidr 15
|
|
89
|
+ while [ 1 ]
|
|
90
|
+ do
|
|
91
|
+ for h in $(nmap -sP -oG - $1 | grep "Up$" | cut -d " " -f 2)
|
|
92
|
+ do
|
|
93
|
+ rehost=$(echo $h|sed 's/\./\\./g')
|
|
94
|
+ if grep -v " $rehost " $2 > /dev/null
|
|
95
|
+ then
|
|
96
|
+ printf "%30s %8s %30s\n" $h "unknw" "unknwn" >> $res_file
|
|
97
|
+ upd_ping $h $2 $3 &
|
|
98
|
+ pid=$!
|
|
99
|
+ cidr_pids="${cidr_pids}\n$pid"
|
|
100
|
+ fi
|
|
101
|
+ done
|
|
102
|
+ done
|
|
103
|
+}
|
|
104
|
+
|
|
105
|
+# prepopulate file
|
71
|
106
|
for h in $(cat "$HOSTS_FILES")
|
72
|
107
|
do
|
73
|
|
- printf "%30s %8s %30s\n" $h "unknw" "unknwn" >> $res_file
|
|
108
|
+ if echo $h |grep -v '/' > /dev/null
|
|
109
|
+ then
|
|
110
|
+ printf "%30s %8s %30s\n" $h "unknw" "unknwn" >> $res_file
|
|
111
|
+ fi
|
74
|
112
|
done
|
75
|
113
|
|
|
114
|
+# run scanners
|
76
|
115
|
for h in $(cat "$HOSTS_FILES" )
|
77
|
116
|
do
|
78
|
|
- upd_ping $h $res_file $lock &
|
|
117
|
+ if echo $h |grep -v '/' > /dev/null
|
|
118
|
+ then
|
|
119
|
+ upd_ping $h $res_file $lock &
|
|
120
|
+ else
|
|
121
|
+ # cidr scan
|
|
122
|
+ cidr_scan $h $res_file $lock &
|
|
123
|
+ fi
|
79
|
124
|
pid=$!
|
80
|
125
|
pids="${pids}\n$pid"
|
81
|
126
|
echo "$h updated by $pid" >&2
|
|
@@ -84,6 +129,7 @@ sleep 1
|
84
|
129
|
|
85
|
130
|
while [ 1 ]
|
86
|
131
|
do
|
|
132
|
+
|
87
|
133
|
semlock $lock
|
88
|
134
|
clear
|
89
|
135
|
echo "Ping radar $($date_cmd)\n"
|