我是实在不会写如何变量内嵌入变量,因此代码写的很繁杂,我再研究下再简化代码
@echo off
cd/d %~dp0
rem c代表当前测试的数目
set c=1
rem b代表总数目
set/A b=6
set/A f=%b%+1
set/a time1=64
title DNS测试
:1
set ip=8.8.8.8
goto ping1
:2
set ip=223.5.5.5
goto ping1
:3
set ip=119.29.29.29
goto ping1
:4
set ip=114.114.114.114
goto ping1
:5
set ip=118.76.76.76
goto ping1
:6
set ip=1.2.4.8
goto ping1
:ping1
cls
echo 已进行%c%项/共%b%项
echo.
echo 正在ping向%ip%
echo.
echo 剩余%time1%秒
for /f "tokens=1-4* delims==" %%a in ('ping /n 3 "%ip%"^|find "平均"') do set "ave%c%=%%d" & set/a time1=%time1%-3
echo 剩余%time1%秒
for /f "tokens=1-4* delims==" %%a in ('ping /n 3 "%ip%"^|find "最短"') do set "min%c%=%%d" & set/a time1=%time1%-3
echo 剩余%time1%秒
for /f "tokens=1-4* delims==" %%a in ('ping /n 3 "%ip%"^|find "最长"') do set "max%c%=%%d" & set/a time1=%time1%-3
echo 剩余%time1%秒
echo 剩余%time1%秒
for /f "tokens=1-4* delims==" %%a in ('ping /n 3 "%ip%"^|find "average"') do set "ave%c%1=%%d" & set/a time1=%time1%-3
echo 剩余%time1%秒
for /f "tokens=1-4* delims==" %%a in ('ping /n 3 "%ip%"^|find "minimum"') do set "min%c%1=%%d" & set/a time1=%time1%-3
echo 剩余%time1%秒
for /f "tokens=1-4* delims==" %%a in ('ping /n 3 "%ip%"^|find "maximum"') do set "max%c%1=%%d" & set/a time1=%time1%-3
echo 剩余%time1%秒
ping/n 2 %ip% > NUL
set/a time1=%time1%-2
if errorlevel 1 (set ave%c%=× & set kdx=×) else set kdx=√
echo 获取%ip%可达性:%kdx%
goto :xs
:xs
if "%ave1%"==""(set ave1=%ave11% & set max1=%max11% & set min1=%min11%)
if "%ave2%"==""(set ave2=%ave21% & set max2=%max21% & set min2=%min21%)
if "%ave3%"==""(set ave3=%ave31% & set max3=%max31% & set min3=%min31%)
if "%ave4%"==""(set ave4=%ave41% & set max4=%max41% & set min4=%min41%)
if "%ave5%"==""(set ave5=%ave51% & set max5=%max51% & set min5=%min51%)
if "%ave6%"==""(set ave6=%ave61% & set max6=%max61% & set min6=%min61%)
cls
set/a c=c+1
if "%C%"=="%F%" (goto end)
goto %c%
:end
echo DNStest
echo ——————————————————————————
echo 名称 服务器IP ave/max/min
echo.
echo 谷歌 8.8.8.8 %ave1%/%max1%/%min1%
echo.
echo 阿里 223.5.5.5 %ave2%/%max2%/%min2%
echo.
echo 腾讯 119.29.29.29 %ave3%/%max3%/%min3%
echo.
echo 114 114.114.114.114 %ave4%/%max4%/%min4%
echo.
echo 百度 118.76.76.76 %ave5%/%max5%/%min5%
echo.
echo cnnic 1.2.4.8 %ave6%/%max6%/%min6%
echo.
pause
exit