forked from maintell/webBenchmark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
77 lines (70 loc) · 1.55 KB
/
main.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
package main
import (
"flag"
"github.com/EDDYCJY/fake-useragent"
"io"
"io/ioutil"
"math/rand"
"net/http"
"sync"
)
const (
letterIdxBits = 6
letterIdxMask = 1<<letterIdxBits - 1
letterIdxMax = 63 / letterIdxBits
)
const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
func RandStringBytesMaskImpr(n int) string {
b := make([]byte, n)
for i, cache, remain := n-1, rand.Int63(), letterIdxMax; i >= 0; {
if remain == 0 {
cache, remain = rand.Int63(), letterIdxMax
}
if idx := int(cache & letterIdxMask); idx < len(letterBytes) {
b[i] = letterBytes[idx]
i--
}
cache >>= letterIdxBits
remain--
}
return string(b)
}
func goFun(Url string,Referer string, wg *sync.WaitGroup){
for true {
client := &http.Client{}
request, err1 := http.NewRequest("GET", Url, nil)
if err1 != nil {
continue
}
if len(Referer) == 0 {
Referer = Url;
}
request.Header.Add("Cookie", RandStringBytesMaskImpr(12))
request.Header.Add("User-Agent", browser.Random())
request.Header.Add("Referer", Referer)
resp, err2 := client.Do(request)
if err2 !=nil{
continue
}
_,err3 :=io.Copy(ioutil.Discard,resp.Body);
if err3 !=nil{
continue
}
}
wg.Done();
}
var count = flag.Int("c",8,"cocurrent thread for download");
var url = flag.String("s","https://baidu.com","target url")
var referer = flag.String("r","","referer url")
func main(){
flag.Parse()
var waitgroup sync.WaitGroup
if(*count<=0){
*count = 8
}
for i:=0; i<*count;i++ {
waitgroup.Add(1)
go goFun(*url,*referer,&waitgroup)
}
waitgroup.Wait()
}