“ping某个IP地址,如果ping不通则在dos窗口或弹出MsgBox提示原因”的批处理bat命令

“ping某个IP地址,如果ping不通则在dos窗口提示原因”的批处理bat命令

@echo off&setlocal enabledelayedexpansion
title Ping检测批处理
mode con cols=88 lines=5&color 0a
::设置要ping的ip地址
set ip=192.168.0.105

::设置要ping的次数
set num=3

echo,&echo 正在对 %ip% 进行 Ping检测,总检测次数为 %num% 次,请耐心等待。。。
set count=%num%
for /l %%a in (1,1,%num%) do (
    title 正在进行第 %%a 次 Ping检测。。。
    ping 127.1 -n "2">nul
    for /f "tokens=4 delims== " %%b in ('ping %ip% -n "1" ^| findstr /c:"平均"') do set ms=%%b
    if not defined ms (
        echo 第 %%a 次 ping 检测失败。
        set /a count-=1
    ) else (
        set /a pms+=!ms:~,-2!
    )
)
cls&echo,&echo 本次 Ping 检测记录了 !count! 次数据,正在计算平均值,请稍等。。。
if not defined pms set msg=网络连接超时,请联系网络管理员。&goto End
set /a ms=!pms!/!count!
if %ms% leq 50 set msg=网络良好。如果还是卡,请联系网络运营商客服反馈。&goto End
if %ms% geq 60 set msg=网络延迟,请联系网络管理员。&goto End
exit
:End
if !count! lss %num% (
    set /a TO=!num!-!count!
    set color=color 0c
    set timeout=(警告:此次检测有 !TO! 次连接超时。)
) else (
    set color=color 0a
)

title Ping检测 -- 检测结果(共检测 %num% 次)
ping 127.1 -n "4">nul
cls&%color%&echo,&echo %msg%%timeout%
echo,&echo 请按任意键退出脚本。
pause>nul&exit

“ping某个IP地址,如果ping不通则弹出MsgBox提示原因”的批处理bat命令

@echo off&setlocal enabledelayedexpansion
title Ping检测批处理
mode con cols=88 lines=5&color 0a
::设置要ping的ip地址
set ip=192.168.0.104

::设置要ping的次数
set num=3

echo,&echo 正在对 %ip% 进行 Ping检测,总检测次数为 %num% 次,请耐心等待。。。
set count=%num%
for /l %%a in (1,1,%num%) do (
    title 正在进行第 %%a 次 Ping检测。。。
    ping 127.1 -n "2">nul
    for /f "tokens=4 delims== " %%b in ('ping %ip% -n "1" ^| findstr /c:"平均"') do set ms=%%b
    if not defined ms (
        echo 第 %%a 次 ping 检测失败。
        set /a count-=1
    ) else (
        set /a pms+=!ms:~,-2!
    )
)
cls&echo,&echo 本次 Ping 检测记录了 !count! 次数据,正在计算平均值,请稍等。。。
if not defined pms echo msgbox "网络连接超时,请联系网络管理员。",64,"提示">alert.vbs && start alert.vbs && ping -n 2 127.1>nul && del alert.vbs &goto End
set /a ms=!pms!/!count!
if %ms% leq 50 set msg=网络良好。如果还是卡,请联系网络运营商客服反馈。 &goto End
if %ms% geq 60 echo msgbox "网络延迟,请联系网络管理员。",64,"提示">alert.vbs && start alert.vbs && ping -n 2 127.1>nul && del alert.vbs &goto End
exit
:End
if !count! lss %num% (
    set /a TO=!num!-!count!
    set color=color 0c
    set timeout=(警告:此次检测有 !TO! 次连接超时。)
) else (
    set color=color 0a
)

title Ping检测 -- 检测结果(共检测 %num% 次)
ping 127.1 -n "4">nul
cls&%color%&echo,&echo %msg%%timeout%
echo,&echo 请按任意键退出脚本。
pause>nul&exit
原文地址:https://www.cnblogs.com/rainbow70626/p/7481378.html