dimanche 12 mai 2019

Trying to ping google and if no respons disable/enable interface

When I startup my computer I don't always have internet right away. I've tried many things but never found a definitive solution to my problem. So what I do now is ping a host. If I can't reach it then I disable and enable my network card.

I have a little batch file that disable and enable the interface. But I would like to create a batch file that launches on startup, tests my ping and if no response then will disable/enable my network interface.

Is this code correct?

@echo on
set "host=google.com"

ping -n 1 "%host%" | findstr /r /c:"[0-9] *ms"

if %errorlevel% == 0 (
    echo Success.
) else (
    set "params=%*"
    cd /d "%~dp0" && ( if exist "%temp%\getadmin.vbs" del "%temp%\getadmin.vbs" ) && fsutil dirty query %systemdrive% 1>nul 2>nul || (  echo Set UAC = CreateObject^("Shell.Application"^) : UAC.ShellExecute "cmd.exe", "/k cd ""%~sdp0"" && %~s0 %params%", "", "runas", 1 >> "%temp%\getadmin.vbs" && "%temp%\getadmin.vbs" && exit /B )
    @echo on
    netsh interface set interface "Ethernet 2" DISABLED
    timeout /t 10
    netsh interface set interface "Ethernet 2" ENABLED
)

I've tried it once but didn't seem to see the ping action or anything on my command prompt.

Aucun commentaire:

Enregistrer un commentaire