很多时候我们需要用ping工具来检测网络的联通性,windows自带ping 工具功能有限。有时候我们需要记录ping的结果,并且需要记录当时的时间。
百度了一下,解决方法如下,复制以下代码到记事本,保存为.vbs文件,如tping.vbs
代码如下:
--------------------------------------------------------------------------------------------------
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()
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
--------------------------------------------------------------------------------------------------
打开CMD,进入到脚本文件所在的目录,执行 " cscript tping.vbs 123.124.125.126 -t > d:1.txt"