标题: 关于自动获取最快速的QQ服务器的问题
[打印本页]
作者: youling126
时间: 2008-5-15 13:12
标题: 关于自动获取最快速的QQ服务器的问题
关于自动获取最快速的QQ服务器的问题
@ echo off
ping sz.tencent.com > a.txt
ping sz1.tencent.com >> a.txt
ping sz2.tencent.com >> a.txt
ping sz3.tencent.com >> a.txt
ping sz4.tencent.com >> a.txt
ping sz5.tencent.com >> a.txt
ping sz6.tencent.com >> a.txt
ping sz7.tencent.com >> a.txt
输入以上代码后可以手动从a.txt中找出最快速的QQ服务器,那么用什么代码能自动判别呢?????????????
作者: HAT
时间: 2008-5-15 13:33
QQlist.txt
Quote: |
sz.tencent.com
sz1.tencent.com
sz2.tencent.com
sz3.tencent.com
sz4.tencent.com
sz5.tencent.com
sz6.tencent.com
sz7.tencent.com |
|
test.bat
@echo off
set MinL=99
set MinT=9999ms
set Best=""
for /f "usebackq" %%a in ("QQlist.txt") do (
call :time %%a
)
echo 最佳服务器:%Best%
echo 最佳服务器的响应时间:%MinT%
goto :eof
:time
for /f "skip=11 tokens=4 delims==" %%a in ('ping %1') do (
if "%%a" equ " 0ms" (
set /a Best=%1
) else (
call :best %%a %1
)
goto :eof
)
:best
for /f "skip=1 delims=:" %%a in ('^(echo %1^&echo.^)^|findstr /o ".*"') do set nowlen=%%a
if "%nowlen%" lss "%MinL%" (
set /a MinL=%nowlen%
set MinT=%1
set Best=%2
) else if "%nowlen%" equ "%MinL%" (
if "%1" lss "%MinT%" (
set MinT=%1
set Best=%2
)
)
goto :eof
作者: HAT
时间: 2008-5-15 13:36
我以前回帖的时候提到过,不同计算机ping的返回结果可能不同,因此代码可能需要做些细微的调整,楼主最好发帖时把自己ping的返回结果一并贴出。
作者: youling126
时间: 2008-5-15 17:59
Quote: |
Originally posted by HAT at 2008-5-15 01:36 PM:
我以前回帖的时候提到过,不同计算机ping的返回结果可能不同,因此代码可能需要做些细微的调整,楼主最好发帖时把自己ping的返回结果一并贴出。 |
|
首先万分感谢HAT兄!!

上次你回帖后我是有把结果贴上去的,可能你没看见
另外我还想问问,能不能把结果直接复制到剪切板
作者: youling126
时间: 2008-5-15 18:55
标题: 感谢HAT兄,顺利运行
我又做了点修改!!不过比较笨,还想麻烦给改一改!!!不甚感激
@echo off
ping sz.tencent.com > QQsev.txt
ping sz1.tencent.com >> QQsev.txt
ping sz2.tencent.com >> QQsev.txt
ping sz3.tencent.com >> QQsev.txt
ping sz4.tencent.com >> QQsev.txt
ping sz5.tencent.com >> QQsev.txt
ping sz6.tencent.com >> QQsev.txt
ping sz7.tencent.com >> QQsev.txt
type QQsev.txt | find "Pinging" >temp.txt
cd. >QQlist.txt
for /f "tokens=3 delims=[] " %%a in (temp.txt) do (echo %%a >>QQlist.txt)
set MinL=99
set MinT=9999ms
set Best=""
for /f "usebackq" %%a in ("QQlist.txt") do (
call :time %%a
)
echo 最佳服务器:%Best% >result.txt
echo 最佳服务器的响应时间:%MinT% >>result.txt
call result.txt
goto :eof
:time
for /f "skip=11 tokens=4 delims==" %%a in ('ping %1') do (
if "%%a" equ " 0ms" (
set /a Best=%1
) else (
call :best %%a %1
)
goto :eof
)
:best
for /f "skip=1 delims=:" %%a in ('^(echo %1^&echo.^)^|findstr /o ".*"') do set
nowlen=%%a
if "%nowlen%" lss "%MinL%" (
set /a MinL=%nowlen%
set MinT=%1
set Best=%2
) else if "%nowlen%" equ "%MinL%" (
if "%1" lss "%MinT%" (
set MinT=%1
set Best=%2
)
)
goto :eof
[
Last edited by youling126 on 2008-5-15 at 07:01 PM ]
作者: HAT
时间: 2008-5-15 20:11
我的建议是在批处理中生成QQlist.txt
如果你用ping生成QQsev.txt的话处理起来会比较麻烦
delims=[]不会以你想象的方式运行
@echo off
echo sz.tencent.com>"QQlist.txt"
echo sz1.tencent.com>>"QQlist.txt"
echo sz2.tencent.com>>"QQlist.txt"
echo sz3.tencent.com>>"QQlist.txt"
echo sz4.tencent.com>>"QQlist.txt"
echo sz5.tencent.com>>"QQlist.txt"
echo sz6.tencent.com>>"QQlist.txt"
echo sz7.tencent.com>>"QQlist.txt"
set MinL=99
set MinT=9999ms
set Best=""
for /f "usebackq" %%a in ("QQlist.txt") do (
call :time %%a
)
echo 最佳服务器:%Best%
echo 最佳服务器的响应时间:%MinT%
goto :eof
:time
for /f "skip=11 tokens=4 delims==" %%a in ('ping %1') do (
if "%%a" equ " 0ms" (
set /a Best=%1
) else (
call :best %%a %1
)
goto :eof
)
:best
for /f "skip=1 delims=:" %%a in ('^(echo %1^&echo.^)^|findstr /o ".*"') do set nowlen=%%a
if "%nowlen%" lss "%MinL%" (
set /a MinL=%nowlen%
set MinT=%1
set Best=%2
) else if "%nowlen%" equ "%MinL%" (
if "%1" lss "%MinT%" (
set MinT=%1
set Best=%2
)
)
goto :eof
作者: zqz0012005
时间: 2008-5-15 20:29
@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
for /f "delims=" %%i in (ip.txt) do (
set st=
(ping -n 1 %%i>nul)&&(set st=%%i)||(echo 999ms %%i>>temp1)
if defined st for /f "tokens=7 delims== " %%t in ('ping -n 1 %%i^|find /i "Reply from"') do echo %%t %%i>>temp1
)
for /f "tokens=1,2" %%a in (temp1) do (
set t=%%a
if "!t:~4,1!"=="" set "t= !t!"
echo !t! %%b>>temp2
)
for /f "tokens=1,2" %%a in ('sort temp2') do (echo %%a %%b>result.txt&del temp1 temp2&start result.txt&exit /b)
作者: terse
时间: 2008-5-15 21:07
@echo off
for /f "delims=" %%a in ('more +11 "%~0"') do for /f "skip=11 tokens=4 delims==" %%i in ('ping %%a') do (
set str=%%i
call set str=00000%%str: =%%
call set str=%%str:~-5%%
call set -%%str%%=%%a
)
for /f "tokens=1,2 delims=0-=" %%i in ('set -') do echo %%j %%i&goto end
:end
pause
exit
sz.tencent.com
sz1.tencent.com
sz2.tencent.com
sz3.tencent.com
sz4.tencent.com
sz5.tencent.com
sz6.tencent.com
sz7.tencent.com
作者: HAT
时间: 2008-5-15 22:23
标题: 7楼
我觉得用ping -n 1的方法不太好,虽然看起来批处理执行的速度会大幅提高,但这样得到的结果可能是“不公平的”,我还是倾向于用ping然后取那个平均响应时间。
作者: youling126
时间: 2008-5-16 00:23
我得声明一下:我最终想要的是最快服务器的IP地址,所以才千辛万苦在前面加了那几段代码。本来可以直接在QQlist.txt写入每个服务器的IP地址,这样可以简化程序,但我发现好像服务器IP地址都不是固定的,会变的,也就要先获取每个服务器的IP地址,所以就有了前面那段代码来获取各服务器的IP地址,不过好像和后面配合不了,所以还想请各位大虾帮忙给改一改
[
Last edited by youling126 on 2008-5-16 at 12:29 AM ]
作者: youling126
时间: 2008-5-16 00:36
标题: 致8##
8楼的比较深奥,看不懂,能不能给解释解释
作者: HAT
时间: 2008-5-16 09:49
Quote: |
Originally posted by youling126 at 2008-5-16 12:23 AM:
我得声明一下:我最终想要的是最快服务器的IP地址,所以才千辛万苦在前面加了那几段代码。本来可以直接在QQlist.txt写入每个服务器的IP地址,这样可 ... |
|
最好一开始就把自己的需要详细的描述清楚,否则有点浪费大家感情哦^_^
因为每个域名后面可能有多台计算机,每次访问时通过loadbalance把用户的请求指派到某一台。
可以先用ping -n 1 -l 1的方法获取一个IP列表,然后再在for里面依次ping这些IP来获取平均响应时间。
作者: youling126
时间: 2008-5-16 14:14
恕我愚昧,还是不明白,能不能具体一点
作者: HAT
时间: 2008-5-16 15:09
@echo off
for /f "skip=3 tokens=1-3" %%a in ('ping -n 1 -l 1 sz.tencent.com') do echo %%c >"QQlist.txt"
for /f "skip=3 tokens=1-3" %%a in ('ping -n 1 -l 1 sz1.tencent.com') do echo %%c >>"QQlist.txt"
for /f "skip=3 tokens=1-3" %%a in ('ping -n 1 -l 1 sz2.tencent.com') do echo %%c >>"QQlist.txt"
for /f "skip=3 tokens=1-3" %%a in ('ping -n 1 -l 1 sz3.tencent.com') do echo %%c >>"QQlist.txt"
for /f "skip=3 tokens=1-3" %%a in ('ping -n 1 -l 1 sz4.tencent.com') do echo %%c >>"QQlist.txt"
for /f "skip=3 tokens=1-3" %%a in ('ping -n 1 -l 1 sz5.tencent.com') do echo %%c >>"QQlist.txt"
for /f "skip=3 tokens=1-3" %%a in ('ping -n 1 -l 1 sz6.tencent.com') do echo %%c >>"QQlist.txt"
for /f "skip=3 tokens=1-3" %%a in ('ping -n 1 -l 1 sz7.tencent.com') do echo %%c >>"QQlist.txt"
set MinL=99
set MinT=9999ms
set Best=""
for /f "usebackq" %%a in ("QQlist.txt") do (
call :time %%a
)
echo 最佳服务器:%Best%
echo 最佳服务器的响应时间:%MinT%
goto :eof
:time
for /f "skip=11 tokens=4 delims==" %%a in ('ping %1') do (
if "%%a" equ " 0ms" (
set /a Best=%1
) else (
call :best %%a %1
)
goto :eof
)
:best
for /f "skip=1 delims=:" %%a in ('^(echo %1^&echo.^)^|findstr /o ".*"') do set nowlen=%%a
if "%nowlen%" lss "%MinL%" (
set /a MinL=%nowlen%
set MinT=%1
set Best=%2
) else if "%nowlen%" equ "%MinL%" (
if "%1" lss "%MinT%" (
set MinT=%1
set Best=%2
)
)
goto :eof
作者: terse
时间: 2008-5-16 16:01
修改一下8楼 没测试
@echo off&setlocal enabledelayedexpansion
echo 请稍候......
for /f "delims=" %%a in ('more +16 "%~0"') do (
set tx=%%a&set var=
for /f "tokens=1-4 delims=[]=" %%i in ('ping %%a^|findstr /i "%%a Average"') do call:LP "%%j" "%%l")
for /f "tokens=1,2 delims=-=0" %%i in ('set -') do echo 最快服务器:%%j IP地址:!%%j! 响应时间%%i&goto end
:end
pause&exit
:LP
if not defined var set var=%~1
if not %2=="" (
set str=%~2&set str=!str: =!
set str=00000000!str!&set str=!str:~-10!
set -!str!=%TX%&set %TX%=!var!
)
goto :eof
sz.tencent.com
sz1.tencent.com
sz2.tencent.com
sz3.tencent.com
sz4.tencent.com
sz5.tencent.com
sz6.tencent.com
sz7.tencent.com