ping带时间戳

1、方法一

打开 powershell命令窗口

ping.exe -t 8.8.8.8 | Foreach{"{0} - {1}" -f (Get-Date),$_} >c:\pingtest.txt

2、方法二

本部分引用前辈的代码。首先创建一个文本文档名字为Pingtest.txt,内容如下:
Dim args, flag, unsuccOut
args=""
otherout=""
flag=0
 
If WScript.Arguments.count = 0 Then
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
End if
 
For i=0 to WScript.Arguments.count - 1
args=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)
 
while Not myping.StdOut.AtEndOfStream
   strLine=myping.StdOut.ReadLine()
'WScript.Echo  "原数据" & chr(9) & strLine
   r=re.Test(strLine)
   If r Then
WScript.Echo date & " "& time & chr(9) & strLine
flag=1
   Else
unsuccOut=unsuccOut & strLine
   End if
Wend
 
if flag = 0 then
WScript.Echo unsuccOut
end if

然后修改本文件Pingtest.txt后缀名为.vbs。即Pingtest.vbs
创建文件的路径以后要用到,注意全英文路径,本示例在D:\下
注意:以上内容编码均使用ANSI编码方式,且空格是在英文状态下输入的

同上,创建一个文本文档名字为Ping.txt,内容如下:
cscript D:\pingtest.vbs 192.168.1.1 -t -l 100 -w 5000>log.txt
1
然后修改本文件Pingtest.txt后缀名为.bat。即Pingtest.bat

参数解读:
D:\pingtst.vbs 为上一步中创建文件的路径
192.168.1.1 修改为你要测试的ip地址,log 为记录日志的文件名
-t 一直ping
-l 封包大小
-w 超时时间

再次注意:
以上内容编码均使用ANSI编码方式,且空格是在英文状态下输入的。
 

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值