Warning: Undefined array key "cperpage" in /www/wwwroot/www.now163.com/wp-content/themes/typology/functions.php on line 230

Warning: Undefined variable $output in /www/wwwroot/www.now163.com/wp-content/themes/typology/functions.php on line 300

Warning: Undefined variable $fixed_tags in /www/wwwroot/www.now163.com/wp-content/themes/typology/functions.php on line 301

Warning: Undefined variable $isshowdots in /www/wwwroot/www.now163.com/wp-content/themes/typology/functions.php on line 302

Warning: Undefined variable $tag_aditional in /www/wwwroot/www.now163.com/wp-content/themes/typology/functions.php on line 305

Warning: Undefined variable $tag_aditional in /www/wwwroot/www.now163.com/wp-content/themes/typology/functions.php on line 308

Warning: Undefined variable $tag_aditional in /www/wwwroot/www.now163.com/wp-content/themes/typology/functions.php on line 311

Warning: Undefined variable $post in /www/wwwroot/www.now163.com/wp-content/themes/typology/functions.php on line 320

Warning: Attempt to read property "ID" on null in /www/wwwroot/www.now163.com/wp-content/themes/typology/functions.php on line 320

Warning: Undefined variable $post in /www/wwwroot/www.now163.com/wp-content/themes/typology/functions.php on line 320

Warning: Attempt to read property "ID" on null in /www/wwwroot/www.now163.com/wp-content/themes/typology/functions.php on line 320

Warning: Undefined variable $more_text_link in /www/wwwroot/www.now163.com/wp-content/themes/typology/functions.php on line 320
为Ping记录加一个时间戳 – 理想社会

为Ping记录加一个时间戳

最近公司网络不稳定,间歇性断流。为了检查网络状况。我们需要用ping来了解网络状况(丢包等等一些问题)。
ping的输出默认是不带时间戳的,所以很难定位故障时间。
下面一个脚本很好的解决了此问题。
代码另存为ping.vbs
用法为:cscript ping.vbs 192.168.1.2 -t > ping.txt
如果ping的输出是英文
那么脚本里的
re.Pattern=”^请求|^来自”
替换为:
re.Pattern=”^Reply|^Request”

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="^请求|^来自"
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

附上一个linux下的方法:

ping baidu.com -c 10 | awk '{ print $0"\t" strftime("%H:%M:%S-%D",systime()) } '

About the author

Add comment

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据

By now163

Your sidebar area is currently empty. Hurry up and add some widgets.