cloverstd / tcping

ping over a tcp connection
MIT License
803 stars 163 forks source link

[add] http proxy #19

Closed sxueck closed 3 years ago

sxueck commented 3 years ago
➜  tcping git:(master) go run . -h
tcping is a ping over tcp connection

Usage:
  tcping host port [flags]

Examples:

  1. ping over tcp
        > tcping google.com
  2. ping over tcp with custom port
        > tcping google.com 443
  3. ping over http
        > tcping -H google.com
  4. ping with URI schema
        > tcping http://hui.lu

Flags:
  -c, --counter int              ping counter (default 4)
  -D, --dns-server stringArray   Use the specified dns resolve server.
      --head                     Use HEAD instead of GET in http mode.
  -h, --help                     help for tcping
  -H, --http                     Use "HTTP" mode. will ignore URI Schema, force to http
  -I, --interval string          ping interval, units are "ns", "us" (or "µs"), "ms", "s", "m", "h" (default "1s")
      --post                     Use POST instead of GET in http mode.
      --proxy string             Use HTTP proxy
  -T, --timeout string           connect timeout, units are "ns", "us" (or "µs"), "ms", "s", "m", "h" (default "1s")
      --user-agent string        Use custom UA in http mode. (default "tcping")
  -v, --version                  show the version and exit

http proxy

➜  tcping git:(master) ✗ go run . https://www.google.com                              
Ping https://www.google.com:443 - failed: Get "https://www.google.com:443": context deadline exceeded (Client.Timeout exceeded while awaiting headers)
Ping https://www.google.com:443 - failed: Get "https://www.google.com:443": context deadline exceeded (Client.Timeout exceeded while awaiting headers)
Ping https://www.google.com:443 - failed: Get "https://www.google.com:443": context deadline exceeded (Client.Timeout exceeded while awaiting headers)
Ping https://www.google.com:443 - failed: Get "https://www.google.com:443": context deadline exceeded (Client.Timeout exceeded while awaiting headers)

Ping statistics https://www.google.com:443
        4 probes sent.
        0 successful, 4 failed.
Approximate trip times:
        Minimum = 0s, Maximum = 0s, Average = 0s

➜  tcping git:(master) ✗ go run . https://www.google.com --proxy http://127.0.0.1:7890
Ping https://www.google.com:443(127.0.0.1:7890) - https is open - time=513.324ms method=GET status=200 bytes=14132
Ping https://www.google.com:443(127.0.0.1:7890) - https is open - time=383.545ms method=GET status=200 bytes=14178
Ping https://www.google.com:443(127.0.0.1:7890) - https is open - time=456.555ms method=GET status=200 bytes=14128
Ping https://www.google.com:443(127.0.0.1:7890) - https is open - time=377.08ms method=GET status=200 bytes=14160

Ping statistics https://www.google.com:443
        4 probes sent.
        4 successful, 0 failed.
Approximate trip times:
        Minimum = 377.08ms, Maximum = 513.324ms, Average = 432.626ms

socks5 proxy

go run . https://www.google.com:443 --http-proxy socks5://127.0.0.1:7890
Ping https://www.google.com:443(127.0.0.1:7890) - https is open - time=634.114ms method=GET status=200 bytes=14196
Ping https://www.google.com:443(127.0.0.1:7890) - https is open - time=889.359ms method=GET status=200 bytes=14104
Ping https://www.google.com:443(127.0.0.1:7890) - https is open - time=393.565ms method=GET status=200 bytes=14191
Ping https://www.google.com:443(127.0.0.1:7890) - https is open - time=393.004ms method=GET status=200 bytes=14165

Ping statistics https://www.google.com:443
        4 probes sent.
        4 successful, 0 failed.
Approximate trip times:
        Minimum = 393.004ms, Maximum = 889.359ms, Average = 577.5105ms
cloverstd commented 3 years ago

看起来代码与描述的不符合,至支持了 http proxy,没有支持 socks5

sxueck commented 3 years ago
 ./tcping --proxy socks5://127.0.0.1:7890 https://google.com
Ping https://google.com:443(127.0.0.1:7890) - https is open - time=888.447ms method=GET status=200 bytes=15233
Ping https://google.com:443(127.0.0.1:7890) - https is open - time=736.187ms method=GET status=200 bytes=15282
Ping https://google.com:443(127.0.0.1:7890) - https is open - time=769.856ms method=GET status=200 bytes=15290
Ping https://google.com:443(127.0.0.1:7890) - https is open - time=733.187ms method=GET status=200 bytes=15246

Ping statistics https://google.com:443
        4 probes sent.
        4 successful, 0 failed.
Approximate trip times:
        Minimum = 733.187ms, Maximum = 888.447ms, Average = 781.91925ms