Set shell = WScript.CreateObject("WScript.Shell")
Set re=New RegExp
re.Pattern = "^Reply|^Request"
Set myping=shell.Exec("ping 192.168.1.1 -t")
while Not myping.StdOut.AtEndOfStream
strLine = myping.StdOut.ReadLine()
r=re.Test(strLine)
If r Then
WScript.Echo date & " "& time & chr(9) & strLine
End if
Wend
将以上代码保存成ping.vbs,在command下执行cscript ping.vbs >>c:\ping.txt(注意要在ping。vbs所在路径下执行)
打开ping.txt就会发现记录了ping的结果和当前时间。