Ping 加時間戳(Windows)

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




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章