@@ -15,6 +15,7 @@ import (
15
15
"strconv"
16
16
"strings"
17
17
"sync"
18
+ "time"
18
19
)
19
20
20
21
const (
@@ -24,13 +25,24 @@ const (
24
25
var mutex sync.Mutex
25
26
26
27
func usage () {
27
- fmt .Printf ("\n USAGE : goSynPortScanner [SourceIP] [SourcePort] [DestIP] [DestPort] \n " )
28
- fmt .Printf ("\n Example : goSynPortScanner 192.168.1.1 1234 8.8.8.8 53 \n \n " )
29
- fmt .Printf ("\t The Source Address of the packet is :\t \t 192.168.1.1 \n " )
30
- fmt .Printf ("\t The Source Port of the packet is :\t \t 1234 \n " )
31
- fmt .Printf ("\t The Destinations Address of the packet is :\t 8.8.8.8 \n " )
32
- fmt .Printf ("\t The Destinations Port of the packet is :\t 53 \n " )
33
- fmt .Printf ("\n Note : You must check that The Destinations Address is legal \n \t And The Source Address should be The Address of Network card\n " )
28
+ fmt .Printf (`
29
+ USAGE : goSynPortScanner [SourceIP] [SourcePort] [DestStartIP]-[DestEndIP] [DestStartPort]-[DestEndPort] [RoutineNum] [IsRandomSrcPort]
30
+
31
+ Example : goSynPortScanner 192.168.1.1 1234 8.8.8.8-8.8.8.9 53-1024 10 true
32
+
33
+ The Source Address of the packet : 192.168.1.1
34
+ The Source Port of the packet : 1234
35
+ The Destination Start Address of the packet : 8.8.8.8
36
+ The Destination End Address of the packet : 8.8.8.8
37
+ The Destination Start Port of the packet : 53
38
+ The Destination End Port of the packet : 1024
39
+ The Routine Number of Will Created : 10
40
+ Whether the source port be random generated : false
41
+
42
+ Note :
43
+ You must check that The Destinations Address is legal
44
+ And The Source Address should be The Address of Network card
45
+ ` )
34
46
}
35
47
36
48
func checkIP (ip string ) {
@@ -221,6 +233,7 @@ func getTaskNum(DestStartAddr string, DestEndAddr string, DestStartPort uint16,
221
233
}
222
234
func main () {
223
235
236
+ runtime .GOMAXPROCS (runtime .NumCPU ())
224
237
if len (os .Args ) < 7 {
225
238
usage ()
226
239
return
@@ -235,7 +248,6 @@ func main() {
235
248
236
249
RoutinueNum := getRoutinueNum ()
237
250
IsRandomSrcPort := getSrcPortOption ()
238
- runtime .GOMAXPROCS (int (RoutinueNum ))
239
251
var i uint32
240
252
taskNum := getTaskNum (DestStartAddr , DestEndAddr , DestStartPort , DestEndPort )
241
253
space := taskNum / RoutinueNum
@@ -247,6 +259,8 @@ func main() {
247
259
248
260
NowDestStartAddr := DestStartAddr
249
261
NowDestStartPort := DestStartPort
262
+
263
+ startTime := time .Now ()
250
264
for i = 0 ; i < InstanceNum ; i ++ {
251
265
worker := new (manager.Worker )
252
266
workers [i ] = * worker
@@ -257,6 +271,7 @@ func main() {
257
271
workers [i ].StartPort = DestStartPort
258
272
workers [i ].EndPort = DestEndPort
259
273
workers [i ].IsRandomSrcPort = IsRandomSrcPort
274
+ workers [i ].RoutineId = int (i )
260
275
var NowDestEndAddr string
261
276
var NowDestEndPort uint16
262
277
@@ -271,7 +286,7 @@ func main() {
271
286
workers [i ].DestEndAddr = NowDestEndAddr
272
287
workers [i ].DestEndPort = NowDestEndPort
273
288
workers [i ].Init ()
274
- channels [i ] = make (chan int , 1 )
289
+ channels [i ] = make (chan int )
275
290
go workers [i ].Run (channels [i ])
276
291
if (InstanceNum - 1 ) != i {
277
292
NowDestStartAddr , NowDestStartPort = nextTask (NowDestEndAddr , NowDestEndPort , DestStartPort , DestEndPort , 1 )
@@ -281,7 +296,12 @@ func main() {
281
296
break
282
297
}
283
298
}
284
- for _ , ch := range channels {
285
- <- ch
299
+
300
+ for _ , v := range channels {
301
+ <- v
302
+ //fmt.Printf("The %d Routine Finish its task\n", <-v)
286
303
}
304
+ endTime := time .Now ()
305
+ elapseTimeSec := float64 (endTime .Sub (startTime ).Nanoseconds ()) / float64 (time .Millisecond )
306
+ fmt .Printf ("All Task is finished,elapse time :%0.3f ms\n " , elapseTimeSec )
287
307
}
0 commit comments