Code Monkey home page Code Monkey logo

tcping's Introduction

tcping

tcping is like tcping.exe, but written with Golang.

Usage

  • The default count of ping is 4.

  • If the port is omitted, the default port is 80.

  • The default interval of ping is 1s.

  • The default timeout of ping is 1s.

ping tcp

> tcping google.com 443
Ping tcp://google.com:443 - Connected - time=15.425732ms
Ping tcp://google.com:443 - Connected - time=2.628025ms
Ping tcp://google.com:443 - Connected - time=2.400356ms
Ping tcp://google.com:443 - Connected - time=1.967587ms

Ping statistics tcp://google.com:443
	4 probes sent.
	4 successful, 0 failed.
Approximate trip times:
	Minimum = 1.967587ms, Maximum = 15.425732ms, Average = 5.605425ms

ping http

> tcping -H hui.lu
Ping http://hui.lu:80 - http is open - time=232.880173ms method=GET status=200 bytes=10317
Ping http://hui.lu:80 - http is open - time=60.096446ms method=GET status=200 bytes=10317
Ping http://hui.lu:80 - http is open - time=56.750403ms method=GET status=200 bytes=10317
Ping http://hui.lu:80 - http is open - time=57.886907ms method=GET status=200 bytes=10317

Ping statistics http://hui.lu:80
	4 probes sent.
	4 successful, 0 failed.
Approximate trip times:
	Minimum = 56.750403ms, Maximum = 232.880173ms, Average = 101.903482ms

tcping's People

Contributors

cloverstd avatar honwen avatar ioslh avatar lushan01 avatar pymumu avatar recall704 avatar ruppde avatar suntong avatar sxueck avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tcping's Issues

net.Dial is not a real dial

The dial is a lazy dial, it will not build a real TCP connection before something transfer through it.
So that, it should send something in TCP ping test.

tcping现有退出码设计不合理

按照Linux命令的设计规范,如果tcping探测一个套接字失败,应该使用异常退出码退出,而非使用正常退出码0退出。
例如:

$ tcping -c 1 128.0.0.1 22
Ping tcp://128.0.0.1:22 - failed: dial tcp 128.0.0.1:22: i/o timeout

Ping statistics tcp://128.0.0.1:22
	1 probes sent.
	0 successful, 1 failed. # 命令执行失败
Approximate trip times:
	Minimum = 0s, Maximum = 0s, Average = 0s

$ echo $?
0 # Linux环境下为正常退出码

在此,给出ping命令的退出码示例:

$ ping -c 1 128.0.0.1
PING 128.0.0.1 (128.0.0.1) 56(84) bytes of data.

--- 128.0.0.1 ping statistics ---
1 packets transmitted, 0 received, 100% packet loss, time 0ms # 命令执行失败
$ echo $?
1 # Linux环境下为异常退出码

tcping 接入管道时出现入参报错

tcping 接入管道时出现入参报错

情境一

echo "127.0.0.1 22" | xargs -i tcping -c 1 ${i}
not a valid uri
... ...

情境二

DEST="127.0.0.1 22,172.16.0.1 22"
IFS=","
for i in ${DEST}; do
    tcping -c 1 ${i}
done

需要作者 @cloverstd 跟进处理一下,否则 tcping 只能当个简单的命令行工具使用

built newest version, then show wrong info

when I running: go build, it shows:
./main.go:5:2: imported and not used: "net"
./main.go:8:2: imported and not used: "strings",
when I remove related packages, then running: tcping baidu.com, it shows:
Ping tcp://:80 - failed: dial tcp :80: connect: connection refused;

Download the app

How do i download or build in Windows machine? I didnt find on readme. Thanks!

Seems every ping after the first one has the wrong timing data

Ping tcp://example.com:80(93.184.216.34:80) - Connected - time=233.248409ms
Ping tcp://example.com:80(93.184.216.34:80) - Connected - time=419.692µs
Ping tcp://example.com:80(93.184.216.34:80) - Connected - time=530.75µs
Ping tcp://example.com:80(93.184.216.34:80) - Connected - time=550.278µs

Ping statistics tcp://example.com:80
	4 probes sent.
	4 successful, 0 failed.
Approximate trip times:
	Minimum = 419.692µs, Maximum = 233.248409ms, Average = 58.687282ms

It should really be returning 200ish ms

I'm accessing the internet through a proxy, so it might have something to do with it

希望提供一个新版本release,并提供官方 mac arms 的预编译

你好,朋友。

最近三年,我在 开发 x-cmd。x-cmd 现在通过自身的 包管理器,提供 了 500+ 的 工具软件快速下载 并使用。
以 yq 为例: https://www.x-cmd.com/pkg/yq
官网还有更多其它的演示

我今天注意到 tcping,觉得这个可以成为 windows tcping 的跨平台版本。但注意到比较久没有更新了,因此并没有提供 mac arm 版本。

虽然 我们 可以 自己来编译,但从 流程透明 和 信任而言,我们更希望 从 官方 提供的二进制 进行转包。

谢谢。

debug

Ping http://127.0.0.1:9999(127.0.0.1:9999) - http is open - time=364.1457ms method=GET status=403 bytes=16
runtime: out of memory: cannot allocate 32768-byte block (1781923840 in use)
fatal error: out of memory
runtime: out of memory: cannot allocate 32768-byte block (1781923840 in use)
fatal error: out of memory
runtime: out of memory: cannot allocate 32768-byte block (1781923840 in use)
fatal error: out of memory

runtime stack:
runtime.throw(0x76bf2e, 0xd)
        /home/go/src/runtime/panic.go:774 +0x64
runtime.getempty(0x0)
        /home/go/src/runtime/mgcwork.go:443 +0x1e4
runtime.(*gcWork).init(0x1141af60)
        /home/go/src/runtime/mgcwork.go:117 +0x1a
runtime.(*gcWork).put(0x1141af60, 0x63e14200)
        /home/go/src/runtime/mgcwork.go:182 +0xb7
runtime.greyobject(0x63e14200, 0xa16400, 0x1008, 0x59873a70, 0x1141af60, 0x1)
        /home/go/src/runtime/mgcmark.go:1283 +0x15b
runtime.scanblock(0xa16400, 0x6ce8, 0xfe2c40, 0x1141af60, 0x0)
        /home/go/src/runtime/mgcmark.go:1087 +0x111
runtime.markrootBlock(0xa16400, 0x6ce8, 0xfe2c40, 0x1141af60, 0x0)
        /home/go/src/runtime/mgcmark.go:251 +0x65
runtime.markroot(0x1141af60, 0x2)
        /home/go/src/runtime/mgcmark.go:161 +0x2be
runtime.gcDrain(0x1141af60, 0x3)
        /home/go/src/runtime/mgcmark.go:915 +0x11f
runtime.gcBgMarkWorker.func2()
        /home/go/src/runtime/mgc.go:1913 +0x6b
runtime.systemstack(0x0)
        /home/go/src/runtime/asm_386.s:399 +0x53
runtime.mstart()
        /home/go/src/runtime/proc.go:1146

goroutine 273 [GC worker (idle)]:
runtime.systemstack_switch()
        /home/go/src/runtime/asm_386.s:360 fp=0x11679f9c sp=0x11679f98 pc=0x44f800
runtime.gcBgMarkWorker(0x1141a600)
        /home/go/src/runtime/mgc.go:1900 +0x1a5 fp=0x11679fe8 sp=0x11679f9c pc=0x418745
runtime.goexit()
        /home/go/src/runtime/asm_386.s:1325 +0x1 fp=0x11679fec sp=0x11679fe8 pc=0x451111
created by runtime.gcBgMarkStartWorkers
        /home/go/src/runtime/mgc.go:1794 +0x61

goroutine 1 [select, 554 minutes]:
main.glob..func1(0xa1a260, 0x114800c0, 0x1, 0x6)
        /home/gopkg/src/github.com/cloverstd/tcping/main.go:150 +0x374
github.com/cloverstd/tcping/vendor/github.com/spf13/cobra.(*Command).execute(0xa1a260, 0x11474008, 0x6, 0x7, 0xa1a260, 0x11474008)
        /home/gopkg/src/github.com/cloverstd/tcping/vendor/github.com/spf13/cobra/command.go:766 +0x1ed
github.com/cloverstd/tcping/vendor/github.com/spf13/cobra.(*Command).ExecuteC(0xa1a260, 0x1146df9c, 0x2, 0x2)
        /home/gopkg/src/github.com/cloverstd/tcping/vendor/github.com/spf13/cobra/command.go:852 +0x243
github.com/cloverstd/tcping/vendor/github.com/spf13/cobra.(*Command).Execute(...)
        /home/gopkg/src/github.com/cloverstd/tcping/vendor/github.com/spf13/cobra/command.go:800
main.main()
        /home/gopkg/src/github.com/cloverstd/tcping/main.go:180 +0xbd

goroutine 19 [syscall, 554 minutes]:
os/signal.signal_recv(0x0)
        /home/go/src/runtime/sigqueue.go:147 +0x12f
os/signal.loop()
        /home/go/src/os/signal/signal_unix.go:23 +0x1a
created by os/signal.init.0
        /home/go/src/os/signal/signal_unix.go:29 +0x37

goroutine 20 [select]:
net/http.(*Transport).getConn(0xa19e40, 0x7f505620, 0x0, 0x7fb0c640, 0x4, 0x7e7e9f10, 0xe, 0x0, 0x0, 0x0, ...)
        /home/go/src/net/http/transport.go:1234 +0x46c
net/http.(*Transport).roundTrip(0xa19e40, 0x7f8d5c00, 0x4a6c7b41, 0x1e4c, 0xa1e3e0)
        /home/go/src/net/http/transport.go:522 +0x503
net/http.(*Transport).RoundTrip(0xa19e40, 0x7f8d5c00, 0xa19e40, 0x6f2309b8, 0xbf96bf57)
        /home/go/src/net/http/roundtrip.go:17 +0x29
net/http.send(0x7f8d5b80, 0x7e9850, 0xa19e40, 0x6f2309b8, 0xbf96bf57, 0x4a6c7b41, 0x1e4c, 0xa1e3e0, 0x1e4c, 0xa1e3e0, ...)
        /home/go/src/net/http/client.go:250 +0x3c3
net/http.(*Client).send(0x7f505580, 0x7f8d5b80, 0x6f2309b8, 0xbf96bf57, 0x4a6c7b41, 0x1e4c, 0xa1e3e0, 0x2, 0xffffffff, 0x7b354a0, ...)
        /home/go/src/net/http/client.go:174 +0xaa
net/http.(*Client).do(0x7f505580, 0x7f8d5b80, 0x0, 0x0, 0x0)
        /home/go/src/net/http/client.go:641 +0x31c
net/http.(*Client).Do(...)
        /home/go/src/net/http/client.go:509
github.com/cloverstd/tcping/ping.HTTPing.ping.func2(0xaf2309b8, 0xbf96bf56)
        /home/gopkg/src/github.com/cloverstd/tcping/ping/http.go:112 +0x8c
github.com/cloverstd/tcping/ping.timeIt(0x11431e9c, 0x7fbb8780, 0x7fbb8740, 0x7ed3e0, 0x7f505560)
        /home/gopkg/src/github.com/cloverstd/tcping/ping/utils.go:13 +0x31
github.com/cloverstd/tcping/ping.HTTPing.ping(0x11480180, 0x1143e200, 0x114801b0, 0x765cdc, 0x3, 0x7, 0x7, 0x6b, 0x0, 0x0, ...)
        /home/gopkg/src/github.com/cloverstd/tcping/ping/http.go:110 +0x3d7
github.com/cloverstd/tcping/ping.(*HTTPing).Start.func1(0x114ac600)
        /home/gopkg/src/github.com/cloverstd/tcping/ping/http.go:51 +0x125
created by github.com/cloverstd/tcping/ping.(*HTTPing).Start
        /home/gopkg/src/github.com/cloverstd/tcping/ping/http.go:41 +0x33

goroutine 165744 [select]:
net/http.setRequestCancel.func3(0x0, 0x7f5055e0, 0x7fb5c5d0, 0x7e7e9f00, 0x7fa21c80)
        /home/go/src/net/http/client.go:321 +0x87
created by net/http.setRequestCancel
        /home/go/src/net/http/client.go:320 +0x20a

goroutine 165745 [GC assist marking]:
syscall.errnoErr(...)
        /home/go/src/syscall/zsyscall_windows.go:34
syscall.Setsockopt(0x3d8, 0xffff, 0x20, 0x1142d8c8, 0x4, 0x0, 0x0)
        /home/go/src/syscall/zsyscall_windows.go:1443 +0xa9 fp=0x1142d8ac sp=0x1142d878 pc=0x497f69
syscall.SetsockoptInt(...)
        /home/go/src/syscall/syscall_windows.go:799
net.setDefaultSockopts(0x3d8, 0x2, 0x1, 0x300, 0x0, 0x0)
        /home/go/src/net/sockopt_windows.go:20 +0x67 fp=0x1142d8d4 sp=0x1142d8ac pc=0x4ed787
net.socket(0x7ed3c0, 0x7fbb8900, 0x765eb6, 0x3, 0x2, 0x1, 0x0, 0x0, 0x7ee960, 0x0, ...)
        /home/go/src/net/sock_posix.go:23 +0x6e fp=0x1142d92c sp=0x1142d8d4 pc=0x4ebb3e
net.internetSocket(0x7ed3c0, 0x7fbb8900, 0x765eb6, 0x3, 0x7ee960, 0x0, 0x7ee960, 0x7f5056a0, 0x1, 0x0, ...)
        /home/go/src/net/ipsock_posix.go:141 +0xf1 fp=0x1142d970 sp=0x1142d92c pc=0x4e3f61
net.(*sysDialer).doDialTCP(0x7fa12d20, 0x7ed3c0, 0x7fbb8900, 0x0, 0x7f5056a0, 0x7e7e9f30, 0xa310d4, 0x6e9b20)
        /home/go/src/net/tcpsock_posix.go:65 +0x86 fp=0x1142d9d0 sp=0x1142d970 pc=0x4eeeb6
net.(*sysDialer).dialTCP(0x7fa12d20, 0x7ed3c0, 0x7fbb8900, 0x0, 0x7f5056a0, 0x4d5db2, 0x2f2309b8, 0xbf96bf5e)
        /home/go/src/net/tcpsock_posix.go:61 +0xa0 fp=0x1142d9f8 sp=0x1142d9d0 pc=0x4eee00
net.(*sysDialer).dialSingle(0x7fa12d20, 0x7ed3c0, 0x7fbb8900, 0x7ebe50, 0x7f5056a0, 0x0, 0x0, 0x0, 0x0)
        /home/go/src/net/dial.go:578 +0x2d9 fp=0x1142da64 sp=0x1142d9f8 pc=0x4d8f69
net.(*sysDialer).dialSerial(0x7fa12d20, 0x7ed3c0, 0x7fbb8900, 0x7aa61f38, 0x1, 0x1, 0x0, 0x0, 0x0, 0x0)
        /home/go/src/net/dial.go:546 +0x214 fp=0x1142db28 sp=0x1142da64 pc=0x4d8764
net.(*Dialer).DialContext(0x1147e140, 0x7ed3e0, 0x7f505560, 0x765eb6, 0x3, 0x7e7e9f10, 0xe, 0x0, 0x0, 0x0, ...)
        /home/go/src/net/dial.go:424 +0x63c fp=0x1142dc54 sp=0x1142db28 pc=0x4d7b6c
net/http.(*Transport).dial(0xa19e40, 0x7ed3e0, 0x7f505560, 0x765eb6, 0x3, 0x7e7e9f10, 0xe, 0x0, 0x432751, 0x1141a604, ...)
        /home/go/src/net/http/transport.go:1040 +0x151 fp=0x1142dcbc sp=0x1142dc84 pc=0x62c821
net/http.(*Transport).dialConn(0xa19e40, 0x7ed3e0, 0x7f505560, 0x0, 0x7fb0c640, 0x4, 0x7e7e9f10, 0xe, 0x0, 0x0, ...)
        /home/go/src/net/http/transport.go:1478 +0x14f9 fp=0x1142df54 sp=0x1142dcbc pc=0x62f689
net/http.(*Transport).dialConnFor(0xa19e40, 0x7fa12cc0)
        /home/go/src/net/http/transport.go:1308 +0x8c fp=0x1142dfe8 sp=0x1142df54 pc=0x62d8ec
created by net/http.(*Transport).queueForDial
        /home/go/src/net/http/transport.go:1277 +0x2b1

runtime stack:
runtime.throw(0x76bf2e, 0xd)
        /home/go/src/runtime/panic.go:774 +0x64
runtime.getempty(0x128ba128)
        /home/go/src/runtime/mgcwork.go:443 +0x1e4
runtime.(*gcWork).init(0x11418960)
        /home/go/src/runtime/mgcwork.go:117 +0x1a
runtime.(*gcWork).tryGet(0x11418960, 0x2e07d52f)
        /home/go/src/runtime/mgcwork.go:272 +0x97
runtime.gcDrainN(0x11418960, 0x10000, 0x0, 0x19ffcc, 0x75be8e00)
        /home/go/src/runtime/mgcmark.go:1018 +0x200
runtime.gcAssistAlloc1(0x128ba0e0, 0x10000, 0x0)
        /home/go/src/runtime/mgcmark.go:512 +0x100
runtime.gcAssistAlloc.func1()
        /home/go/src/runtime/mgcmark.go:423 +0x2e
runtime.systemstack(0x44f752)
        /home/go/src/runtime/asm_386.s:399 +0x53
runtime.mstart()
        /home/go/src/runtime/proc.go:1146

runtime stack:
runtime.throw(0x76bf2e, 0xd)
        /home/go/src/runtime/panic.go:774 +0x64
runtime.getempty(0x134)
        /home/go/src/runtime/mgcwork.go:443 +0x1e4
runtime.(*gcWork).init(0x11419c60)
        /home/go/src/runtime/mgcwork.go:117 +0x1a
runtime.(*gcWork).put(0x11419c60, 0x1148c000)
        /home/go/src/runtime/mgcwork.go:182 +0xb7
runtime.greyobject(0x1148c000, 0xa1d100, 0x10, 0xfdb0e8, 0x11419c60, 0x0)
        /home/go/src/runtime/mgcmark.go:1283 +0x15b
runtime.scanblock(0xa1d100, 0x13ed4, 0xfe2fa9, 0x11419c60, 0x0)
        /home/go/src/runtime/mgcmark.go:1087 +0x111
runtime.markrootBlock(0xa1d100, 0x13ed4, 0xfe2fa9, 0x11419c60, 0x0)
        /home/go/src/runtime/mgcmark.go:251 +0x65
runtime.markroot(0x11419c60, 0x3)
        /home/go/src/runtime/mgcmark.go:166 +0x23a
runtime.gcDrain(0x11419c60, 0x7)
        /home/go/src/runtime/mgcmark.go:915 +0x11f
runtime.gcBgMarkWorker.func2()
        /home/go/src/runtime/mgc.go:1936 +0x12f
runtime.systemstack(0x0)
        /home/go/src/runtime/asm_386.s:399 +0x53
runtime.mstart()
        /home/go/src/runtime/proc.go:1146

tcping -H http://127.0.0.1:9999 -c 0 -T 2s

Not working with IPv6 destination address: too many colons in address

I tried to tcping 2603:1040:401:5::1a, tried the following syntax:

./tcping [2603:1040:401:5::1a]
./tcping [2603:1040:401:5::1a] 9201
./tcping 2603:1040:401:5::1a

None of them worked. Log:

PC➜  tcping git:(master) ./tcping [2603:1040:401:5::1a]
Ping tcp://2603:1040:401:5::1a:80() Failed(dial tcp: address 2603:1040:401:5::1a:80: too many colons in address) - time=13.49µs dns=0s
Ping tcp://2603:1040:401:5::1a:80() Failed(dial tcp: address 2603:1040:401:5::1a:80: too many colons in address) - time=6.51µs dns=0s
^C
Ping statistics tcp://2603:1040:401:5::1a:80
	2 probes sent.
	0 successful, 2 failed.
Approximate trip times:
	Minimum = 6.51µs, Maximum = 13.49µs, Average = 10µs⏎

PC➜  tcping git:(master) ./tcping [2603:1040:401:5::1a] 9201
Ping tcp://2603:1040:401:5::1a:9201() Failed(dial tcp: address 2603:1040:401:5::1a:9201: too many colons in address) - time=10.37µs dns=0s
Ping tcp://2603:1040:401:5::1a:9201() Failed(dial tcp: address 2603:1040:401:5::1a:9201: too many colons in address) - time=6.37µs dns=0s
Ping tcp://2603:1040:401:5::1a:9201() Failed(dial tcp: address 2603:1040:401:5::1a:9201: too many colons in address) - time=5.81µs dns=0s
Ping tcp://2603:1040:401:5::1a:9201() Failed(dial tcp: address 2603:1040:401:5::1a:9201: too many colons in address) - time=6.56µs dns=0s

Ping statistics tcp://2603:1040:401:5::1a:9201
	4 probes sent.
	0 successful, 4 failed.
Approximate trip times:
	Minimum = 5.81µs, Maximum = 10.37µs, Average = 7.277µs⏎ 

PC➜  tcping git:(master) ./tcping 2603:1040:401:5::1a
2603:1040:401:5::1a is an invalid target.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.