diff --git a/README.md b/README.md index 1a9eaf8..f4fb256 100644 --- a/README.md +++ b/README.md @@ -5,8 +5,9 @@ http benchmark tool to ran out your server bandwidth. - random User-Agent on every Request - customizable Referer Url, +- customizable header, - concurrent routines as you wish, depends on you server performance. -- add http post mode +- http post mode - specify multi target ip, or resolved by system dns. - randomly X-Forwarded-For and X-Real-IP (default on). @@ -25,6 +26,8 @@ http benchmark tool to ran out your server bandwidth. target url (default "https://baidu.com") -i string custom ip address for that domain, multiple addresses automatically will be assigned randomly + -H http header pattern + http header pattern, use Random with number prefix will generate random string, same key will be overwritten -f string randomized X-Forwarded-For and X-Real-IP address -p string @@ -37,10 +40,16 @@ http benchmark tool to ran out your server bandwidth. ## Advanced example # send request to 10.0.0.1 and 10.0.0.2 for https://target.url with 32 concurrent threads - # and refer is https://refer.url - ./webBenchmark_linux_x64 -c 32 -s https://target.url -r https://refer.url -i 10.0.0.1 -i 10.0.0.2 + # and refer is https://refer.url + ./webBenchmark_linux_x64 -c 32 -s https://target.url -r https://refer.url -i 10.0.0.1 -i 10.0.0.2 + # send request to https://target.url with header regid:123 and sign:Random10 + ./webBenchmark_linux_x64 -s https://target.url -H 'regid:123' -H 'sign:QpXDYHdVzB' + + + + +## LICENSE AND DISCLAIMER -##LICENSE AND DISCLAIMER **1. Application.** diff --git a/main.go b/main.go index 35a3311..0aa5dec 100644 --- a/main.go +++ b/main.go @@ -13,6 +13,7 @@ import ( "math/rand" "net/http" "os" + "strconv" "strings" "sync" "time" @@ -44,6 +45,33 @@ const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" var SpeedQueue = list.New() var SpeedIndex uint64 = 0 + + +type header struct { + key, value string +} + +type headersList []header + +func (h *headersList) String() string { + return fmt.Sprint(*h) +} + +func (h *headersList) IsCumulative() bool { + return true +} + +func (h *headersList) Set(value string) error { + res := strings.SplitN(value, ":", 2) + if len(res) != 2 { + return nil + } + *h = append(*h, header{ + res[0], strings.Trim(res[1], " "), + }) + return nil +} + type ipArray []string func (i *ipArray) String() string { @@ -269,6 +297,27 @@ func goFun(Url string, postContent string, Referer string, XforwardFor bool, cus request.Header.Add("X-Real-IP", randomip) } + if len(headers)>0 { + for _, head := range headers { + headKey := head.key + headValue := head.value + if strings.HasPrefix(head.key,"Random") { + count, convErr := strconv.Atoi(strings.ReplaceAll(head.value, "Random", "")) + if convErr==nil { + headKey = RandStringBytesMaskImpr(count) + } + } + if strings.HasPrefix(head.value,"Random"){ + count, convErr := strconv.Atoi(strings.ReplaceAll(head.value, "Random", "")) + if convErr==nil { + headValue = RandStringBytesMaskImpr(count) + } + } + request.Header.Del(headKey) + request.Header.Set(headKey, headValue) + } + } + resp, err2 := client.Do(request) if err2 != nil { continue @@ -287,6 +336,7 @@ var referer = flag.String("r", "", "referer url") var xforwardfor = flag.Bool("f", true, "randomized X-Forwarded-For and X-Real-IP address") var TerminalWriter = goterminal.New(os.Stdout) var customIP ipArray +var headers headersList func usage() { fmt.Fprintf(os.Stderr, @@ -309,6 +359,7 @@ webBenchmark -c 16 -s https://some.website -r https://referer.url func main() { flag.Var(&customIP, "i", "custom ip address for that domain, multiple addresses automatically will be assigned randomly") + flag.Var(&headers, "H", "custom header") flag.Usage = usage flag.Parse() if *h {