Skip to content
This repository was archived by the owner on Jan 13, 2024. It is now read-only.

Commit e09e324

Browse files
committed
Feat: timeout
1 parent 621c2e3 commit e09e324

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

main.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"flag"
55
"fmt"
6+
"time"
67
"udpflood/attack"
78
)
89

@@ -11,13 +12,15 @@ var (
1112
_port uint
1213
_threads uint64
1314
_size uint64
15+
_time uint
1416
)
1517

1618
func init() {
1719
flag.StringVar(&_host, "h", "localhost", "host")
1820
flag.UintVar(&_port, "p", 8080, "port")
1921
flag.Uint64Var(&_threads, "t", 100, "threads")
2022
flag.Uint64Var(&_size, "s", 65507, "packet size")
23+
flag.UintVar(&_time, "time", 10, "time")
2124
flag.Parse()
2225
}
2326

@@ -26,6 +29,7 @@ func main() {
2629
fmt.Printf("port: %d\n", _port)
2730
fmt.Printf("threads: %d\n", _threads)
2831
fmt.Printf("size: %d\n", _size)
32+
fmt.Printf("time duration: %ds\n", _time)
2933
fmt.Print("Attack started...\n")
3034

3135
fullAddr := fmt.Sprintf("%s:%d", _host, _port)
@@ -35,5 +39,12 @@ func main() {
3539
return
3640
}
3741

38-
<-make(chan bool, 1)
42+
times := time.After(time.Second * time.Duration(_time))
43+
44+
select {
45+
case <-make(chan bool, 1):
46+
case <-times:
47+
fmt.Printf("Attack finished\n")
48+
return
49+
}
3950
}

0 commit comments

Comments
 (0)