linux+ping获取时间戳,Tools:实现ping操作带时间戳【windows+linux】

【windows下】:

ping.vbs

Dim args, flag, unsuccOut

args=""otherout=""flag=0If WScript.Arguments.count= 0Then

WScript.Echo"Usage: cscript tping.vbs [-t] [-a] [-n count] [-l size] [-f] [-i TTL] [-v TOS]"WScript.Echo"[-s count] [[-j host-list] | [-k host-list]]"WScript.Echo"[-r count] [-w timeout] destination-list"wscript.quit

EndifFor i=0 to WScript.Arguments.count - 1args=args & " " &WScript.Arguments(i)

Next

Set shell= WScript.CreateObject("WScript.Shell")

Set re=New RegExp

re.Pattern="^Reply|^Request|^来自|^请求"Set myping=shell.Exec("ping" &args)whileNot myping.StdOut.AtEndOfStream

strLine=myping.StdOut.ReadLine()‘WScript.Echo "原数据" & chr(9) & strLine

r=re.Test(strLine)

If r Then

WScript.Echodate & " "& time & chr(9) &strLine

flag=1Else

unsuccOut=unsuccOut &strLine

EndifWendif flag = 0 thenWScript.Echo unsuccOut

endif

ping.bat

cscript ping.vbs 10.8.115.127 -n 10 >ping_log.txt

执行ping.bat即可

效果如下:

Microsoft (R) Windows Script Host Version 5.812

版权所有(C) Microsoft Corporation。保留所有权利。

2018/11/19 14:17:13来自 10.8.115.115 的回复: 字节=32 时间<1ms TTL=200

2018/11/19 14:17:14来自 10.8.115.115 的回复: 字节=32 时间<1ms TTL=200

2018/11/19 14:17:15来自 10.8.115.115 的回复: 字节=32 时间<1ms TTL=200

2018/11/19 14:17:16来自 10.8.115.115 的回复: 字节=32 时间=1ms TTL=200

【linux下】

ping $1 |while read line;do echo `date`$line;done >> ping_test.log

效果:

root@/root/chen#ping 10.8.210.101 |while read line;do echo `date`$line;done

Mon Nov 19 14:23:42 CST 2018PING 10.8.210.101 (10.8.210.101) 56(84) bytes of data.

Mon Nov 19 14:23:42 CST 201864 bytes from 10.8.210.101: icmp_seq=1 ttl=64 time=0.257 ms

Mon Nov 19 14:23:43 CST 201864 bytes from 10.8.210.101: icmp_seq=2 ttl=64 time=0.163 ms

Mon Nov 19 14:23:44 CST 201864 bytes from 10.8.210.101: icmp_seq=3 ttl=64 time=0.141 ms

Mon Nov 19 14:23:45 CST 201864 bytes from 10.8.210.101: icmp_seq=4 ttl=64 time=0.160 ms

Mon Nov 19 14:23:46 CST 201864 bytes from 10.8.210.101: icmp_seq=5 ttl=64 time=0.148 ms

原文:https://www.cnblogs.com/channy14/p/9982926.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值