|
@@ -32,7 +32,7 @@ clean_exit() {
|
32
|
32
|
for pid in $(echo $pids)
|
33
|
33
|
do
|
34
|
34
|
echo killing $pid
|
35
|
|
- kill $pid
|
|
35
|
+ kill $pid 2>/dev/null
|
36
|
36
|
done
|
37
|
37
|
for pid in $(echo $pids)
|
38
|
38
|
do
|
|
@@ -44,16 +44,22 @@ clean_exit() {
|
44
|
44
|
exit 0
|
45
|
45
|
}
|
46
|
46
|
|
|
47
|
+cidr_nmap_pid=""
|
|
48
|
+cidr_nmap_res=""
|
47
|
49
|
cidr_pids=""
|
48
|
50
|
clean_cidr() {
|
49
|
51
|
echo "CIDR killed, cleaning..."
|
50
|
|
- for pid in $(echo $cidr_pids)
|
|
52
|
+
|
|
53
|
+ kill $cidr_nmap_pid 2>/dev/null
|
|
54
|
+
|
|
55
|
+ for pid in $(echo $cidr_pids $cidr_nmap_pid)
|
51
|
56
|
do
|
52
|
57
|
echo CIDR killing $pid
|
53
|
|
- kill $pid
|
|
58
|
+ kill $pid 2>/dev/null
|
54
|
59
|
wait $pid
|
55
|
60
|
echo CIDR $pid killed
|
56
|
61
|
done
|
|
62
|
+ rm -v $cidr_nmap_res
|
57
|
63
|
exit 0
|
58
|
64
|
}
|
59
|
65
|
|
|
@@ -116,15 +122,31 @@ cidr_scan() {
|
116
|
122
|
# $4 delay
|
117
|
123
|
|
118
|
124
|
test -z "$4" && delay=5 || delay=$4
|
|
125
|
+ cidr_nmap_res=$(mktemp -t ping_radar_cidr_nmap.XXXXXXXX)
|
|
126
|
+ nmap_cmd="nmap -sP -oG $cidr_nmap_res --max-rate=15 $1"
|
119
|
127
|
|
120
|
128
|
trap clean_cidr 15
|
|
129
|
+
|
|
130
|
+ #nmap -sP -oG "$cidr_nmap_res" $1 >/dev/null &
|
|
131
|
+ $nmap_cmd >/dev/null &
|
|
132
|
+ cidr_nmap_pid=$!
|
|
133
|
+
|
121
|
134
|
while [ 1 ]
|
122
|
135
|
do
|
123
|
|
- semlock $lock
|
124
|
|
- echo "CIDR scanning $1" >&2
|
125
|
|
- semrelease $lock
|
126
|
|
-
|
127
|
|
- for h in $(nmap -sP -oG - $1 | grep "Up$" | cut -d " " -f 2)
|
|
136
|
+ if kill -0 $cidr_nmap_pid 2> /dev/null
|
|
137
|
+ then
|
|
138
|
+ semlock $lock
|
|
139
|
+ echo "CIDR scanning $1" >&2
|
|
140
|
+ semrelease $lock
|
|
141
|
+ rerun=0
|
|
142
|
+ else
|
|
143
|
+ semlock $lock
|
|
144
|
+ echo "CIDR scanned $1" >&2
|
|
145
|
+ semrelease $lock
|
|
146
|
+ rerun=1
|
|
147
|
+ fi
|
|
148
|
+
|
|
149
|
+ for h in $(cat $cidr_nmap_res | grep "Up$" | cut -d " " -f 2)
|
128
|
150
|
do
|
129
|
151
|
rehost=$(echo $h|sed 's/\./\\./g')
|
130
|
152
|
if grep " $rehost " $2 > /dev/null
|
|
@@ -142,11 +164,12 @@ cidr_scan() {
|
142
|
164
|
fi
|
143
|
165
|
done
|
144
|
166
|
|
145
|
|
- semlock $lock
|
146
|
|
- echo "CIDR scanned $1" >&2
|
147
|
|
- semrelease $lock
|
148
|
|
-
|
149
|
167
|
sleep $delay
|
|
168
|
+ if [ $rerun -eq 1 ]
|
|
169
|
+ then
|
|
170
|
+ $nmap_cmd >/dev/null &
|
|
171
|
+ cidr_nmap_pid=$!
|
|
172
|
+ fi
|
150
|
173
|
done
|
151
|
174
|
}
|
152
|
175
|
|