Skip to content

Commit

Permalink
add customizable header
Browse files Browse the repository at this point in the history
  • Loading branch information
maintell committed Jan 11, 2022
1 parent b0c2b2d commit 9ffaa98
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 4 deletions.
17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand All @@ -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
Expand All @@ -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.**

Expand Down
51 changes: 51 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"math/rand"
"net/http"
"os"
"strconv"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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 {
Expand Down

0 comments on commit 9ffaa98

Please sign in to comment.