-
Notifications
You must be signed in to change notification settings - Fork 13
/
rate.go
78 lines (70 loc) · 1.59 KB
/
rate.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package main
import (
"flag"
"fmt"
"io/ioutil"
"net/http"
"os"
"sync"
)
var threads int
var method string
var link string
var code int
var cont bool
func main() {
var wg sync.WaitGroup
var channel = make(chan int)
var times int
flag.StringVar(&method, "X", "HEAD", "method")
flag.IntVar(&threads, "t", 10, "threads")
flag.IntVar(×, "a", 500, "times")
flag.BoolVar(&cont, "s", false, "continue after the code changing")
flag.StringVar(&link, "u", "", "url")
flag.Parse()
if link == "" {
fmt.Println("URL was not provided")
return
}
req, _ := http.NewRequest(method, link, nil) //,nil
req.Header.Add("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36")
resp, err := (*http.Client).Do(&http.Client{}, req)
if err == nil {
code = resp.StatusCode
} else {
fmt.Println(err.Error())
}
for t := 0; t < threads; t++ {
go func() {
for {
i := <-channel
wg.Add(1)
request(i)
wg.Done()
}
}()
}
for i := 0; i < times; i++ {
channel <- i
}
wg.Wait()
}
func request(i int) {
client := &http.Client{}
req, _ := http.NewRequest(method, link, nil)
req.Header.Add("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36")
resp, err := client.Do(req)
if err != nil {
println(err.Error())
return
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
println(err.Error())
}
resp.Body.Close()
fmt.Println(i, resp.StatusCode, len(body))
if code != resp.StatusCode && !cont {
os.Exit(5)
}
}