diff --git a/README.md b/README.md index 453db60..1a9eaf8 100644 --- a/README.md +++ b/README.md @@ -7,13 +7,13 @@ http benchmark tool to ran out your server bandwidth. - customizable Referer Url, - concurrent routines as you wish, depends on you server performance. - add http post mode -- specify target ip, or resolved by system dns. +- specify multi target ip, or resolved by system dns. - randomly X-Forwarded-For and X-Real-IP (default on). # Todo - automatically tune concurrent routines to gain maximum performance. -- randomly target ip. - support NOT standard port in address with specify target ip. +- subscription benchmark task from remote server. # Usage webBenchmark -c [COUNT] -s [URL] -r [REFERER] @@ -24,7 +24,7 @@ http benchmark tool to ran out your server bandwidth. -s string target url (default "https://baidu.com") -i string - customize ip + custom ip address for that domain, multiple addresses automatically will be assigned randomly -f string randomized X-Forwarded-For and X-Real-IP address -p string @@ -36,11 +36,12 @@ http benchmark tool to ran out your server bandwidth. ./webBenchmark_linux_x64 -c 32 -s https://target.url ## Advanced example - # send request to 1.1.1.1 for https://target.url with 32 concurrent threads + # 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 1.1.1.1 + ./webBenchmark_linux_x64 -c 32 -s https://target.url -r https://refer.url -i 10.0.0.1 -i 10.0.0.2 ##LICENSE AND DISCLAIMER + **1. Application.** Please read this document carefully before using, accessing, downloading, installing or otherwise operating the webBenchmark as defined hereafter. diff --git a/build.bat b/build.bat index 13595a3..07a61ae 100644 --- a/build.bat +++ b/build.bat @@ -8,7 +8,4 @@ SET GOARCH=arm go build -o webBenchmark_linux_arm SET GOOS=windows SET GOARCH=amd64 -go build -o webBenchmark_x64.exe -SET GOOS=windows -SET GOARCH=arm -go build -o webBenchmark_x64_arm.exe \ No newline at end of file +go build -o webBenchmark_x64.exe \ No newline at end of file diff --git a/main.go b/main.go index 65cf2e8..35a3311 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "container/list" "context" + "crypto/tls" "flag" "fmt" "github.com/EDDYCJY/fake-useragent" @@ -30,7 +31,7 @@ import ( const ( letterIdxBits = 6 - letterIdxMask = 1< 0 { dialer := &net.Dialer{ Timeout: 30 * time.Second, KeepAlive: 30 * time.Second, } - http.DefaultTransport.(*http.Transport).DialContext = func(ctx context.Context, network, addr string) (net.Conn, error) { + transport.DialContext = func(ctx context.Context, network, addr string) (net.Conn, error) { rand.Seed(time.Now().Unix()) ip := customIP[rand.Intn(len(customIP))] - if strings.HasPrefix(addr,"https"){ + if strings.HasPrefix(addr, "https") { addr = ip + ":443" - } else if strings.HasPrefix(addr,"http") { + } else if strings.HasPrefix(addr, "http") { + addr = ip + ":80" + } else { + addr = ip + ":80" + } + return dialer.DialContext(ctx, network, addr) + } + transport.DialTLSContext = func(ctx context.Context, network, addr string) (net.Conn, error) { + rand.Seed(time.Now().Unix()) + ip := customIP[rand.Intn(len(customIP))] + if strings.HasPrefix(addr, "https") { + addr = ip + ":443" + } else if strings.HasPrefix(addr, "http") { addr = ip + ":80" } else { addr = ip + ":80" @@ -226,7 +245,10 @@ func goFun(Url string, postContent string, Referer string, XforwardFor bool, cus var request *http.Request var err1 error = nil - client := &http.Client{} + client := &http.Client{ + Transport: transport, + Timeout: time.Second*10, + } if len(postContent) > 0 { request, err1 = http.NewRequest("POST", Url, strings.NewReader(postContent)) } else { @@ -251,14 +273,13 @@ func goFun(Url string, postContent string, Referer string, XforwardFor bool, cus if err2 != nil { continue } - _, err3 := io.Copy(ioutil.Discard, resp.Body) - if err3 != nil { - continue - } + io.Copy(ioutil.Discard, resp.Body) + resp.Body.Close() + } wg.Done() } - +var h = flag.Bool("h", false, "this help") var count = flag.Int("c", 16, "concurrent thread for download,default 8") var url = flag.String("s", "https://baidu.com", "target url") var postContent = flag.String("p", "", "post content") @@ -267,9 +288,33 @@ var xforwardfor = flag.Bool("f", true, "randomized X-Forwarded-For and X-Real-IP var TerminalWriter = goterminal.New(os.Stdout) var customIP ipArray +func usage() { + fmt.Fprintf(os.Stderr, +`webBenchmark version: /0.4 +Usage: webBenchmark [-c concurrent] [-s target] [-p] [-r refererUrl] [-f] [-i ip] + +Options: +`) + flag.PrintDefaults() + fmt.Fprintf(os.Stderr, +` +Advanced Example: +webBenchmark -c 16 -s https://some.website -r https://referer.url -i 10.0.0.1 -i 10.0.0.2 + 16 concurrent to benchmark https://some.website with https://referer.url directly to ip 10.0.0.1 and 10.0.0.2 +webBenchmark -c 16 -s https://some.website -r https://referer.url + 16 concurrent to benchmark https://some.website with https://referer.url to dns resolved ip address + +`) +} + func main() { flag.Var(&customIP, "i", "custom ip address for that domain, multiple addresses automatically will be assigned randomly") + flag.Usage = usage flag.Parse() + if *h { + flag.Usage() + return + } routines := *count if customIP != nil && len(customIP) > 0 && routines < len(customIP){