1
@echo off
if "%1"=="" goto :syntax
if "%1"=="/?" goto :syntax
if "%1"=="/" goto :syntax
if "%1"=="?" goto :syntax
if "%1"=="/help" goto :syntax
if "%2"=="" (set tt=2000) else set tt=%2
:disp
mode con:cols=100 lines=25
color f5
title *****ping命令加强脚本(含时间戳)*****
echo.
echo. _____________sping.cmd written by hitme_____________
echo.
echo. =============================================================================
echo. *主机名* *日期与时间* *时延* CTRL+C结束
echo. -----------------------------------------------------------------------------
(
echo. _____________sping.cmd written by hitme_____________
echo.
echo. ==============================================================================
echo. *主机名* *日期与时间* *时延* CTRL+C结束
echo. -----------------------------------------------------------------------------
) >log.txt
:loop
ping -n 2 %1 | find "Reply" >nul|| goto:error
setlocal ENABLEDELAYEDEXPANSION
for /f "tokens=4 delims==" %%i in ('ping -n 3 -l 256 %1^|findstr "Average"') do (
set dt=%date:~4% %time:~0,-3%
set n=%%i
set /a m = !n:~0,-3! / 5
set x=
for /l %%a in (1,1,!m!) do set x=!x!=
if "!n:~0,-1!"==" 0ms" (
echo %1 !dt! ^<10ms ^|=^>
echo %1 !dt! ^<10ms ^|=^> >>log.txt ) else (
echo %1 !dt! !n:~0,-1! ^|!x!=^>
echo %1 !dt! !n:~0,-1! ^|!x!=^> >>log.txt)
)
ping -n 1 -w %tt% 127.0.0.1 2>nul >nul
goto:loop
:error
echo. %1 %date:~4% %time:~0,-3% REPLY无........................
echo. %1 %date:~4% %time:~0,-3% REPLY无........................>>log.txt
ping -n 10 127.0.0.1 2>nul >nul
endlocal
goto:loop
:syntax
cls
echo.
echo.sping.cmd
echo.
echo.written by hitme 2005.08.19
echo.===============================================
echo.用法:
echo. sping ip or hostname 时间间隔
echo.
echo.例如:
echo. sping bbs.et8.net 10000(单位豪秒)
echo. sping 192.168.1.1
echo.===============================================
pause
-----------------以上内容另存为sping.cmd
2
'如果想输出到文件中记录下来可以
'E:\>cscript ping.vbs www.sse.com.cn -t -l 1000 -w 5000>sseping.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
-------ping.vbs