我想创建一个批处理文件,该文件将在执行ping命令后自动将“抖动”结果输出到屏幕上。
C:\ Ping Google.com
Reply from 172.217.11.174: bytes=32 time=9ms TTL=56
Reply from 172.217.11.174: bytes=32 time=9ms TTL=56
Reply from 172.217.11.174: bytes=32 time=9ms TTL=56
Reply from 172.217.11.174: bytes=32 time=9ms TTL=56
http://www.3rdechelon.net/jittercalc.asp有一个计算器,如果可以将其复制/粘贴到该正方形/字段中,则会显示抖动结果。
据我所知,“抖动是对来自Ping的每个返回消息之间的差异(Δ时间或增量时间)的度量”。
我希望将其输出到屏幕,而不是复制/粘贴到该网站。
答案 0 :(得分:2)
根据我对使用this article的理解,“要测量抖动,我们先取样本之间的差,然后除以样本数量(减1)。”这意味着我们将必须将数据放入数组并对其进行一些数学运算。
使用示例,这些延迟:136、184、115、148、125-我们采用前两个延迟,将其相减,然后对所有示例执行此操作以求出差异。
48、69、33、23是我们的区别。从这里我们需要找到所有4个结果的“均值”。为此,我们将它们全部加起来(173),然后除以4。这就是我的脚本所做的。查看我在脚本中留下的所有笔记。
Jitter.bat
@ECHO OFF
@Setlocal EnableDelayedExpansion
Rem | Configuration
Rem | Address - The Address You Wish To PING
Rem | PingAmount - The Amount Of Times To Ping Each Cycle
set "Address=google.com"
set "PingAmount=10"
:LOOP
Set "SUM1=0"
Set "SUM2=0"
Set "WHOLE=0"
Set "MEAN=0"
Set "RUN=0"
set "MAX=0"
Set "TOTAL=0"
Echo Waiting For Ping Data...
Rem | Change The Ping Command To Strings
FOR /F "tokens=1-4,5,*" %%A in ('Ping -n %PingAmount% "%Address%" ^| Find /I "Reply"') DO (
Rem | This is optional; Will Display Whole "Ping"
Echo %%A %%B %%C %%D [%%E] %%F
Rem | Grab Only "Time="
FOR /F "tokens=1,* delims==" %%G in ('echo %%E') DO (
Rem | Edit "Time=" String To Extract Only The Time
Set "String=%%H"
Set String=!String:ms=!%
Rem | Do Math
IF "!WHOLE!"=="2" (
Rem | Compare Strings & Sort
If "!SUM1!"=="!String!" (
Set "MAX=!Sum1!"
Set "MIN=!String!"
) ELSE (
Rem | Find Largest
for %%A in (!SUM1!, !String!) do (
set n=%%A
if !n! GTR !MAX! set MAX=!n!
)
Rem | Find Smallest
for %%A in (!SUM1!, !String!) do (
set n=%%A
if !n! LSS !MAX! set MIN=!n!
)
Rem | Subtract 1st string from new
Set /a "SUM2=!MAX!-!MIN!"
)
Rem | Add Each Differences
Set /a "TOTAL=TOTAL+!SUM2!"
Rem | Save Last Response
Set "SUM1=!String!"
) ELSE (
Rem | First Cycle, Set First String
Set "SUM1=!String!"
Rem | Disable This Check
Set "WHOLE=2"
)
)
)
Rem | Do Math
Set /a "TRESULTS=!PingAmount!-1"
set /a "MEAN=!TOTAL!/!TRESULTS!"
Rem | Display Jitter
Echo The Jitter For The Above Arry Is: Jitter=!MEAN!ms
Echo(
goto LOOP
要获取有关任何命令的帮助,请执行以下操作:
call /?
set /?
for /?
if /?
find /?