本帖最后由 Echo11 于 2022-11-8 09:01 编辑
稍微改了下,增加了对4次全部丢失的情况的处理。- @ECHO off
- ECHO.提示:netsh 需要管理员权限,请以管理员权限运行本脚本.
- setlocal EnableDelayedExpansion
- SET "IP1="
- SET "IP2="
- SET "IP3="
- ECHO.请稍等...&ECHO.
- CALL :PingDNS 223.5.5.5
- CALL :PingDNS 114.114.114.114
- CALL :PingDNS 180.76.76.76
- CALL :PingDNS 119.29.29.29
- CALL :PingDNS 8.8.8.8
- ECHO.执行以下命令:
- IF defined IP1 netsh int ip add dns "WLAN" %IP1% index=1
- IF defined IP2 netsh int ip add dns "WLAN" %IP2% index=2
- IF defined IP3 netsh int ip add dns "WLAN" %IP3% index=3
- pause
- GOTO:EOF
-
- :PingDNS <dnsIP>
- for /f "tokens=1-9 delims==m " %%a in ('ping -n 4 %~1 ^| find "平均"') do ECHO.%~1 的平均时间:%%fms&SET %~1_time=%%f
- REM 对于4次全部丢失的,不显示平均时间,故直接丢弃
- IF not %errorlevel%==0 ECHO.%~1 全部丢失!&GOTO:EOF
- CALL :CMP %~1
- GOTO:EOF
-
- :CMP <IP>
- IF not defined IP1 SET "IP1=%~1"&EXIT /B 1
- IF not defined IP2 SET "IP2=%~1"&EXIT /B 2
- IF not defined IP3 SET "IP3=%~1"&EXIT /B 3
- IF !%~1_time! LSS !%IP1%_time! SET "IP3=%IP2%"&SET "IP2=%IP1%"&SET "IP1=%~1"&EXIT /B 1
- IF !%~1_time! LSS !%IP2%_time! SET "IP3=%IP2%"&SET "IP2=%~1"&EXIT /B 2
- IF !%~1_time! LSS !%IP3%_time! SET "IP3=%~1"&EXIT /B 3
- EXIT /B 0
复制代码
|