前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >tcping在linux用法,tcping的安装和使用[通俗易懂]

tcping在linux用法,tcping的安装和使用[通俗易懂]

作者头像
全栈程序员站长
发布2022-09-09 20:47:57
8.3K0
发布2022-09-09 20:47:57
举报

大家好,又见面了,我是你们的朋友全栈君。

Tcping 网上比较少资料是关于linux对tcp端口ping测试的方法,我这里简单介绍2种方法: 1.yum安装,编译安装方法 1-1.wget http://linuxco.de/tcping/tcping-1.3.5.tar.gz ###下载tcping

ab1b5ad394a75b3b9a4e9dc5e9836561.png
ab1b5ad394a75b3b9a4e9dc5e9836561.png

1-2 tar zxvf tcping-1.3.5.tar.gz ####解压缩tcping-1.3.5

1-3 cd tcping-1.3.5 ###进入文件夹

1-4 gcc -o tcping tcping.c ####编译执行文件

866b5b82047b36e23568d5316daf44d8.png
866b5b82047b36e23568d5316daf44d8.png

1-5 ./tcping www.baidu.com 80 ####使用方法,后面加tcp端口

26b85c6d538429baf0cf08d34200f431.png
26b85c6d538429baf0cf08d34200f431.png

2.通过shell脚本,执行tcping命令(能长ping) 2-1 脚本如下: #!/bin/sh

ver=”v1.7″ format=”%Y%m%d%H%M%S” d=”no” c=”no” C=”no” ttl=255 seq=0 q=1 r=1 w=3 topts=””

usage () { name=basename $0 echo “tcpping $ver Richard van den Berg ” echo echo “Usage: $name [-d] [-c] [-C] [-w sec] [-q num] [-x count] ipaddress [port]” echo echo ” -d print timestamp before every result” echo ” -c print a columned result line” echo ” -C print in the same format as fping’s -C option” echo ” -w wait time in seconds (defaults to 3)” echo ” -r repeat every n seconds (defaults to 1)” echo ” -x repeat n times (defaults to unlimited)” echo echo “See also: man tcptraceroute” echo }

_checksite() { ttr=tcptraceroute -f ${ttl} -m ${ttl} -q ${q} -w ${w} $* 2>&1 if echo “${ttr}” | egrep -i “(bad destination|got roo)” >/dev/null 2>&1; then echo “${ttr}” exit fi }

_testsite() { myseq=”${1}” shift [ “${c}” = “yes” ] && nows=date +${format} [ “${d}” = “yes” ] && nowd=date ttr=tcptraceroute -f ${ttl} -m ${ttl} -q ${q} -w ${w} $* 2>/dev/null host=echo “${ttr}” | awk ‘{print $2 ” ” $3}’ rtt=echo “${ttr}” | sed ‘s/.*] //’ | awk ‘{print $1}’ not=echo “${rtt}” | tr -d “.0123456789” [ “${d}” = “yes” ] && echo “$nowd” if [ “${c}” = “yes” ]; then if [ “x${rtt}” != “x” -a “x${not}” = “x” ]; then echo “$myseq $nows $rtt $host” else echo “$myseq $nows $max $host” fi elif [ “${C}” = “yes” ]; then if [ “$myseq” = “0” ]; then echo -n “$1 :” fi if [ “x${rtt}” != “x” -a “x${not}” = “x” ]; then echo -n ” $rtt” else echo -n ” -” fi if [ “$x” = “1” ]; then echo fi else echo “${ttr}” | sed -e “s/^.*.$/seq $myseq: no response (time out)/” -e “s/^$ttl /seq $myseq: tcp response from/” fi

echo “${ttr}”

}

while getopts dhq:w:cr:nNFSAEi:f:l:m:p:s:x:C opt ; do case “$opt” in d|c|C) eval $opt=”yes” ;; q|w|r|x) eval $opt=”$OPTARG” ;; n|N|F|S|A|E) topt=”$topt -$opt” ;; i|l|p|s) topt=”$topt -$opt $OPTARG” ;; f|m) ttl=”$OPTARG” ;; ?) usage; exit ;; esac done

shift expr $OPTIND – 1

if [ “x$1” = “x” ]; then usage exit fi

#max=echo “${w} * 1000” | bc

if [ date +%s != “%s” ]; then format=”%s” fi

_checksite ${topt} $*

if [ “$x” = “” ]; then while [ 1 ] ; do _testsite ${seq} ${topt} $* & pid=$! if [ “${C}” = “yes” ]; then wait $pid fi seq=expr $seq + 1 sleep ${r} done else while [ “$x” -gt 0 ] ; do _testsite ${seq} ${topt} $* & pid=$! if [ “${C}” = “yes” ]; then wait $pid fi seq=expr $seq + 1 x=expr $x – 1 if [ “$x” -gt 0 ]; then sleep ${r} fi done fi

exit

2-2 vi一个文件,这里命名为tcping

fc01ee91065aa226ce6243c1fc131dbb.png
fc01ee91065aa226ce6243c1fc131dbb.png

2-3 chmod 777 tcping ###赋予tcping执行权限

1bbc5744858919fcc9da386280061497.png
1bbc5744858919fcc9da386280061497.png

2-4 安装脚本执行内容所需软件支持

1.wget

2.rpm -ih tcptraceroute-1.5-0.beta7.el6.rf.x86_64.rpm

4c0386e724e7d9bfd50654acf53ec288.png
4c0386e724e7d9bfd50654acf53ec288.png

2-6 ./tcping www.baidu.com 80 ####执行shell脚本

e2c7a1c48e0ab2a04a6a81cac0e54845.png
e2c7a1c48e0ab2a04a6a81cac0e54845.png

由睿江云运维人员提供,想了解更多,请登陆www.eflycloud.com

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/152495.html原文链接:https://javaforall.cn

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档