TCP端口检测、网络连接时延测试工具 tcping

发表时间:2019-11-05 15:22 | 分类:Linux | 浏览:3,416 次

在主流的linux系统中,通过yum或者apt也可安装tcping,不过通过源安装的tcping只能显示单次检测的结果,也没有具体的连接时延。现参考windows版tcping,用python写了一个linux环境下的类似工具。

代码

建立socket连接,测试端口连通性和网络连接时延。

def tcp(ip, port, timeout=2):
    sk = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sk.settimeout(timeout)
    try:
        t1 = time.time()
        sk.connect((ip, port))
        t2 = time.time()
        sk.close()
        return True, int(round((t2-t1)*1000))
    except Exception:
        sk.close()
        return False, timeout*1000

完整代码:https://github.com/zhangnq/scripts/blob/master/python/tcping.py

使用方法

下载

输入如下命令下载安装。

wget http://download.chekiang.info/tool/tcping -O /usr/bin/tcping
chmod +x /usr/bin/tcping

参数介绍

必选参数:
destination a DNS name, an IP address
可选参数:
-h, --help show this help message and exit
-p PORT a numeric TCP port, 1-65535. If not specified, defaults to 80.
-t ping continuously until stopped via control-c.
-n NUMBER send count pings and then stop, default 4.
-i INTERVAL wait seconds between pings, default 1.
-w WAIT wait seconds for a response, default 2.
-v, --version print version and exit.

使用举例

tcping zhangnq.com
tcping 114.114.114.114 -t -p 53
tcping zhangnq.com -n 10 -p 443 -i 5 -w 1

结果

默认和ping一样只发送四个检测包,-t参数表示持续检测,ctrl+c退出。

tcping for linux result

附:Windows tcping下载

网址:https://elifulkerson.com/projects/tcping.php

本文标签:

本文链接:https://www.sijitao.net/3158.html

欢迎您在本博客中留下评论,如需转载原创文章请注明出处,谢谢!

已经有2个回复
Comment (2)
Trackbacks (0)
  1. 在线教育培训系统  ( 2019.11.6 14:13 ) : #-9

    不错 很赞

  2. 夏日博客  ( 2019.11.9 21:02 ) : #-8

    赞赞赞

  1. 还没有Trackbacks
一键脚本 博客历程 留言联系 文章归档 网站地图 谷歌地图
Copyright © 2010-2024 章郎虫博客 All Rights Reserved.