Giter Site home page Giter Site logo

tcping's Introduction

Tcping

中文

The Tcping is a network tool. which is similar with ping.

We often use the network is based on tcp, So use tcping more accurately.

Usage

pip install tcping
➜  ~ tcping api.github.com
Connected to api.github.com[:80]: seq=1 time=236.44 ms
Connected to api.github.com[:80]: seq=2 time=237.99 ms
Connected to api.github.com[:80]: seq=3 time=248.88 ms
Connected to api.github.com[:80]: seq=4 time=233.51 ms
Connected to api.github.com[:80]: seq=5 time=249.23 ms
Connected to api.github.com[:80]: seq=6 time=249.77 ms
Connected to api.github.com[:80]: seq=7 time=235.82 ms
Connected to api.github.com[:80]: seq=8 time=242.30 ms
Connected to api.github.com[:80]: seq=9 time=248.26 ms
Connected to api.github.com[:80]: seq=10 time=251.77 ms

--- api.github.com[:80] tcping statistics ---
10 connections, 10 successed, 0 failed, 100.00% success rate
minimum = 233.51ms, maximum = 251.77ms, average = 243.40ms

GFW Fucking.

➜  ~ tcping --help
Usage: tcping [OPTIONS] HOST

Options:
  -p, --port INTEGER      Tcp port
  -c, --count INTEGER     Try connections counts
  -t, --timeout FLOAT     Timeout seconds
  --report / --no-report  Show report to replace statistics
  --help  

the result is ascii table by using --report.

➜  ~ tcping api.github.com -c 3 --report
Connected to api.github.com[:80]: seq=1 time=237.79 ms
Connected to api.github.com[:80]: seq=2 time=237.72 ms
Connected to api.github.com[:80]: seq=3 time=258.53 ms

+----------------+------+-----------+--------+--------------+----------+----------+----------+
|      Host      | Port | Successed | Failed | Success Rate | Minimum  | Maximum  | Average  |
+----------------+------+-----------+--------+--------------+----------+----------+----------+
| api.github.com |  80  |     3     |   0    |   100.00%    | 237.72ms | 258.53ms | 244.68ms |
+----------------+------+-----------+--------+--------------+----------+----------+----------+

The return code can be catch by some real-time test tools. Following is an example:

import subprocess as sp

# Print the return code (status=0 mean ping success)
status = sp.call(['tcping', '-c', '1', '-t', '1', 'github.com'], stdout=sp.DEVNULL, stderr=sp.DEVNULL)
print(status)

# OR print the full message
status = sp.run(['tcping', '-c', '1', '-t', '1', 'github.com'], stdout=sp.DEVNULL, stderr=sp.DEVNULL)
print(status)

END

Huh, I just want to check my VPS's network status.

tcping's People

Contributors

sakurai-youhei avatar sma11black avatar zhengxiaowai 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

tcping's Issues

Add flag for success

To code against this library without spawning subprocesses I have to reference internal variables to know if the connection was a success. Having a method to determine success would be helpful.

def do_ping(target, port = 80):
  ping = Ping(target, port)
  ping.ping(1)
  rc = (ping._successed > ping._failed)

今天使用测试了您的模块程序

import subprocess as sp

Print the return code (status=0 mean ping success)

status = sp.call(['tcping', '-c', '1', '-t', '1', 'github.com'], stdout=sp.DEVNULL, stderr=sp.DEVNULL)
print(status)

OR print the full message

status = sp.run(['tcping', '-c', '1', '-t', '1', 'github.com'], stdout=sp.DEVNULL, stderr=sp.DEVNULL)
print(status)

上面这段代码我在测试的时候发现,不管github.com 这个位置填写的 ip地址还是域名是否能连通,它返回的都会返回0,按您上面描述0等于可以ping通。不知道是为什么。

ping time不应该包含dns解析时间吧?

ubuntu@ubuntu-pc:~$ ./tcping example.com 22
Ping tcp://example.com:22(145.28.112.37:22) - Connected - time=250.081038ms
Ping tcp://example.com:22(145.28.112.37:22) - Connected - time=259.093898ms
Ping tcp://example.com:22(145.28.112.37:22) - Connected - time=253.900446ms
Ping tcp://example.com:22(145.28.112.37:22) - Connected - time=253.49524ms

Ping statistics tcp://example.com:22
        4 probes sent.
        4 successful, 0 failed.
Approximate trip times:
        Minimum = 250.081038ms, Maximum = 259.093898ms, Average = 254.142655ms
ubuntu@ubuntu-pc:~$ ./tcping 145.28.112.37 22
Ping tcp://145.28.112.37:22(145.28.112.37:22) - Connected - time=75.645099ms
Ping tcp://145.28.112.37:22(145.28.112.37:22) - Connected - time=71.512504ms
Ping tcp://145.28.112.37:22(145.28.112.37:22) - Connected - time=61.02463ms
Ping tcp://145.28.112.37:22(145.28.112.37:22) - Connected - time=59.13156ms

Ping statistics tcp://145.28.112.37:22
        4 probes sent.
        4 successful, 0 failed.
Approximate trip times:
        Minimum = 59.13156ms, Maximum = 75.645099ms, Average = 66.828448ms

时间计算应该是在DNS解析成功后,connect开始计算。
不能把DNS解析时间算上。

by pinging a hostname instead of an IP, errors do not count as "failed"

When I ping a hostname, which can not be resolved, I get this error:

>>> ping.ping(1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/dist-packages/tcping.py", line 171, in ping
    ((self._host, self._port), None))
  File "/usr/local/lib/python3.6/dist-packages/tcping.py", line 108, in cost
    func(*arg)
  File "/usr/local/lib/python3.6/dist-packages/tcping.py", line 45, in connect
    self._s.connect((host, int(port)))
socket.gaierror: [Errno -2] Name or service not known

However, this does not count as failed:

>>> ping._failed
0

socket.error: [Errno 61] Connection refused

Traceback (most recent call last):
File "/usr/local/bin/tcping", line 11, in
sys.exit(cli())
File "/usr/local/lib/python2.7/site-packages/click/core.py", line 764, in call
return self.main(*args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/click/core.py", line 717, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python2.7/site-packages/click/core.py", line 956, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python2.7/site-packages/click/core.py", line 555, in invoke
return callback(*args, **kwargs)
File "/usr/local/bin/tcping.py", line 205, in cli
ping.ping(count)
File "/usr/local/bin/tcping.py", line 171, in ping
((self._host, self._port), None))
File "/usr/local/bin/tcping.py", line 108, in cost
func(*arg)
File "/usr/local/bin/tcping.py", line 45, in connect
self._s.connect((host, int(port)))
File "/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 228, in meth
return getattr(self._sock,name)(*args)
socket.error: [Errno 61] Connection refused

Quiet mode

I need to use this from existing python code without spawning new processes without having it print to standard out with each execution. My scripts run in kubernates and having the output going to standard out without an override increases my logs quickly.

几个RTT?

s.connect <-> s.shutdown 在tcp层是一个包的RTT时间吗? 还是包括了三次握手以及 fin+ack的2.5RTT呢?

可以增加 ipv6 么?

一直用大佬的 tcping 版本 , 不知道能不能增加 ipv6 的 tcp ping 功能 .
毕竟直接用 pip3 install tcping 太方便了 .

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.