Batch ERRORLEVEL ping response

前端 未结 13 1715
走了就别回头了
走了就别回头了 2020-12-14 23:05

I\'m trying to use a batch file to confirm a network connection using ping. I want to do batch run and then print if the ping was successful or not. The problem is that it a

13条回答
  •  时光取名叫无心
    2020-12-14 23:54

    I needed to reset a wifi connection because it has issues. This was my quick solution.

    @echo off
    Rem Microsoft Windows 10 ping test to gateway.
    Rem Run batch file from an administrative command prompt.
    
    cls
    :starting
    Rem Send one ping to the gateway.  Write the results to a file.
    ping 192.168.1.1 -n 1 > pingtest.txt
    
    Rem Search for unreachable in the file. 
    c:\windows\system32\findstr.exe "unreachable" pingtest.txt
    
    Rem errorlevel 0 reset the adapter if 1 then wait 10 minutes and test again
    if %errorlevel%==1 goto waiting
    
    Rem unreachable was found reset the adapter.
    
    Rem write the date and time the reset was done.
    echo Reset date: %date% time: %time% >> resettimes.txt
    
    Rem issue netsh interface show interface to find your adapter's name to reset
    Rem my adapter is "wi-fi"
    
    netsh interface set interface "wi-fi" disable
    timeout /t  5
    netsh interface set interface "wi-fi" enable
    :waiting
    echo "It is online waiting 10 minutes"
    timeout /t  600
    goto starting
    

提交回复
热议问题