我想知道是否有可能(以及如何)检测网络连接是否随时崩溃。我已经创建了一个带有检查功能的小脚本,但它每隔几秒就通过一次ping检查网络,但它运行不正常。我被告知没有检测到微切口。
这是来源:
@echo off
:: Interval of time the network is checked: 30 seconds
set delay_time=30
:: Delay between the kill and the start of the process
set delay_time_kill_start=5
:: Example process to kill and start
set process_to_kill=calc.exe
set process_to_start=calc.exe
:: local network to ping to check the connection
set ping_url=10.51.111.223 -n 1 -w 1000
:test-connection
Ping %ping_url%
if errorlevel 1 (
echo No hay conexión
:is-connected
Ping %ping_url%
if errorlevel 1 (
@echo on
echo trying to connect
@echo off
timeout 10
goto :is-connected
) else (
@echo on
echo kill the process
@echo off
taskkill /IM %process_to_kill% /f
timeout %delay_time_kill_start%
@echo on
echo start the process
@echo off
%process_to_start%
goto test-connection
)
) else (
timeout %delay_time%
goto test-connection
)
pause
基本上我想要的是杀死进程并在网络连接随时丢失时再次启动它,因为当连接崩溃时该进程会冻结。
所以我想检查,例如,如果网络连接在过去半小时内的任何时间丢失,则每30分钟一次,如果是,则杀死并启动该过程。
是否可以每隔几秒钟不执行ping策略?