Browse Source

Nmap results enhancement + nmap limitations

Now nmap is limited with a --max-rate set to 15 packets per seconds (
when scanning 4 range with the default value the networks begin to
collapse...)
And now nmap is run in background, allowing CIDR scanning processes
to regulary check the nmap result and add new ping processes.
Yann Weber 7 years ago
parent
commit
348bb265a1
1 changed files with 35 additions and 12 deletions
  1. 35
    12
      ping_radar.sh

+ 35
- 12
ping_radar.sh View File

32
 	for pid in $(echo $pids)
32
 	for pid in $(echo $pids)
33
 	do
33
 	do
34
 		echo killing $pid
34
 		echo killing $pid
35
-		kill $pid
35
+		kill $pid 2>/dev/null
36
 	done
36
 	done
37
 	for pid in $(echo $pids)
37
 	for pid in $(echo $pids)
38
 	do
38
 	do
44
 	exit 0
44
 	exit 0
45
 }
45
 }
46
 
46
 
47
+cidr_nmap_pid=""
48
+cidr_nmap_res=""
47
 cidr_pids=""
49
 cidr_pids=""
48
 clean_cidr() {
50
 clean_cidr() {
49
 	echo "CIDR killed, cleaning..."
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
 	do
56
 	do
52
 		echo CIDR killing $pid
57
 		echo CIDR killing $pid
53
-		kill $pid
58
+		kill $pid 2>/dev/null
54
 		wait $pid
59
 		wait $pid
55
 		echo CIDR $pid killed
60
 		echo CIDR $pid killed
56
 	done
61
 	done
62
+	rm -v $cidr_nmap_res
57
 	exit 0
63
 	exit 0
58
 }
64
 }
59
 
65
 
116
 	# $4 delay
122
 	# $4 delay
117
 
123
 
118
 	test -z "$4" && delay=5 || delay=$4
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
 	trap clean_cidr 15
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
 	while [ 1 ]
134
 	while [ 1 ]
122
 	do
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
 		do
150
 		do
129
 			rehost=$(echo $h|sed 's/\./\\./g')
151
 			rehost=$(echo $h|sed 's/\./\\./g')
130
 			if grep " $rehost " $2 > /dev/null
152
 			if grep " $rehost " $2 > /dev/null
142
 			fi
164
 			fi
143
 		done
165
 		done
144
 
166
 
145
-		semlock $lock
146
-		echo "CIDR scanned $1" >&2
147
-		semrelease $lock
148
-
149
 		sleep $delay
167
 		sleep $delay
168
+		if [ $rerun -eq 1 ]
169
+		then
170
+			$nmap_cmd >/dev/null &
171
+			cidr_nmap_pid=$!
172
+		fi
150
 	done
173
 	done
151
 }
174
 }
152
 
175
 

Loading…
Cancel
Save