批量排列多个网站的ping命令? [英] Arrange the pinging of multiple website in order with batch?
问题描述
我已经搜索了,但是找不到能做到这一点的方法.
I have searched but can not find a method that would do this.
这是一个可对我所玩游戏的服务器执行ping操作的批次,以便我能够找到最适合我的服务器.
This is a batch that pings the servers of a game I play, so that I am able to find the best server for me.
有没有办法让我对所有服务器执行ping操作,然后按从最慢的响应到最高的响应顺序列出它们?
Is there a way I can have it ping all the servers then list them in order from the slowest response to the highest?
感谢您的帮助!
@TITLE OSRS Ping Checker
@ECHO off
SET usaworlds=5,6,7,13,14,15,19,20,21,22,23,24,29,30,31,32,37,38,39,40,45,46,47,48,53,54,55,56,57,61,62,69,70,74,77,78,86,117
@ECHO ---------------------------------------------------
@ECHO USA
@ECHO ---------------------------------------------------
FOR %%i IN (%usaworlds%) DO (
Echo | SET /p=World %%i
FOR /F "tokens=5" %%a IN ('Ping oldschool%%i.runescape.com -n 1 ^| FIND "time="') DO Echo %%a
)
PAUSE
推荐答案
@ECHO off
setlocal enabledelayedexpansion
TITLE OSRS Ping Checker
for /f %%a in ('copy /Z "%~dpf0" nul') do set "CR=%%a"
del x.tmp 2>nul
SET usaworlds=5,6,7,13,14,15,19,20,21,22,23,24,29,30,31,32,37,38,39,40,45,46,47,48,53,54,55,56,57,61,62,69,70,74,77,78,86,117
ECHO ---------------------------------------------------
ECHO USA
ECHO ---------------------------------------------------
FOR %%i IN (%usaworlds%) DO (
<nul set /p "=checking World %%i !CR!"
FOR /F "tokens=5" %%a IN ('Ping oldschool%%i.runescape.com -n 1 ^| FIND "TTL="') DO (
for /f "tokens=2 delims==" %%b in ("%%a") do (
set tim=00000%%b
set tim=!tim:~-7,-2!
)
)
echo !tim! World %%i>>x.tmp
)
for /f "tokens=3" %%c in ('sort /r x.tmp') do set fastest=%%c
echo fastest response from World %fastest%
PAUSE
注意:一次ping的时间不可靠(请使用ping -t
检查不同的时间),因此这种方法可能会给您带来错误的结果.最好用ping -n 5
或更高的值选择"Average",但这当然会降低脚本的性能.
Note: the time of a one-time ping isn't reliable (check the different times with ping -t
) and so this approach may give you false results. better check "Average" with ping -n 5
or even higher, but that will of course decrease the performance of the script.
要使用平均时间使其更快,更可靠,您可以并行运行ping(我已经使用了
To make it faster and more reliable using the average times, you can run the pings in parallel (I have used that method years ago in another context)
@ECHO off
setlocal
TITLE OSRS Ping Checker
for /f %%a in ('copy /Z "%~dpf0" nul') do set "CR=%%a"
del %temp%\x.tmp 2>nul
SET usaworlds=wrgl,5,6,7,13,14,15,19,20,21,22,23,24,29,30,31,32,37,38,39,40,45,46,47,48,53,54,55,56,57,61,62,69,70,74,77,78,86,117
@ECHO ---------------------------------------------------
@ECHO USA
@ECHO ---------------------------------------------------
FOR %%i IN (%usaworlds%) DO (
start /min "Pinging" cmd /v:on /c "(FOR /F "tokens=9 delims= " %%a IN ('Ping oldschool%%i.runescape.com -n 5^|findstr /e "ms"') do set avrg= %%a)& >> %temp%\x.tmp echo ^!avrg:~-7,-2^!" World %%i
)
:wait
timeout 1 >nul
tasklist /FI "WINDOWTITLE eq Pinging" |find ".exe" >nul && goto :wait
for /f "tokens=3" %%c in ('sort /r %temp%\x.tmp') do set fastest=%%c
echo fastest response from World %fastest%
PAUSE
使用start /min
而不是start /b
确实可以在出现错误的情况下使屏幕保持干净(使其速度变慢,但您不会注意到它)
Using start /min
instead of start /b
does keep your screen clean in case of errors (makes it a bit slower, but you won't notice it)
这篇关于批量排列多个网站的ping命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!