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

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

@echo off&setlocal enabledelayedexpansion
title Ping检测批处理
mode con cols= lines=&color 0a
::设置要ping的ip地址
set ip=192.168.0.105 ::设置要ping的次数
set num= echo,&echo 正在对 %ip% 进行 Ping检测,总检测次数为 %num% 次,请耐心等待。。。
set count=%num%
for /l %%a in (,,%num%) do (
title 正在进行第 %%a 次 Ping检测。。。
ping 127.1 -n "">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-=
) else (
set /a pms+=!ms:~,-!
)
)
cls&echo,&echo 本次 Ping 检测记录了 !count! 次数据,正在计算平均值,请稍等。。。
if not defined pms set msg=网络连接超时,请联系网络管理员。&goto End
set /a ms=!pms!/!count!
if %ms% leq set msg=网络良好。如果还是卡,请联系网络运营商客服反馈。&goto End
if %ms% geq 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 "">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= lines=&color 0a
::设置要ping的ip地址
set ip=192.168.0.104 ::设置要ping的次数
set num= echo,&echo 正在对 %ip% 进行 Ping检测,总检测次数为 %num% 次,请耐心等待。。。
set count=%num%
for /l %%a in (,,%num%) do (
title 正在进行第 %%a 次 Ping检测。。。
ping 127.1 -n "">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-=
) else (
set /a pms+=!ms:~,-!
)
)
cls&echo,&echo 本次 Ping 检测记录了 !count! 次数据,正在计算平均值,请稍等。。。
if not defined pms echo msgbox "网络连接超时,请联系网络管理员。",,"提示">alert.vbs && start alert.vbs && ping -n 127.1>nul && del alert.vbs &goto End
set /a ms=!pms!/!count!
if %ms% leq set msg=网络良好。如果还是卡,请联系网络运营商客服反馈。 &goto End
if %ms% geq echo msgbox "网络延迟,请联系网络管理员。",,"提示">alert.vbs && start alert.vbs && ping -n 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 "">nul
cls&%color%&echo,&echo %msg%%timeout%
echo,&echo 请按任意键退出脚本。
pause>nul&exit
上一篇:批处理(bat)实现SQLServer数据库备份与还原


下一篇:Java执行批处理.bat文件(有问题???求高手帮忙解答!!!)