GCRaistlin
Silver Member | Редактировать | Профиль | Сообщение | Цитировать | Сообщить модератору
Код: @echo off rem Exit codes: rem 0 Connected rem 1 Disconnected rem 2 Not found rem -1 Invalid syntax rem If your Windows (or user profile) isn't English: rem Type 'ipconfig /all > ipconfig.txt' while the connection you want to check rem state of is disconnected, then look for the connection in the ipconfig.txt. rem You'll see something like this: rem --------------------------------------------------------------------------- rem Ethernet adapter Local Area Connection 2: rem rem Media State . . . . . . . . . . . : Media disconnected rem --------------------------------------------------------------------------- rem ^^^^^^^^^^^ rem It's what the 'String' environment variable should be set to. setlocal set "String=Media State" echo check_connection v1.0 echo (c) 2016 GCRaistlin [gcraistlin@yandex.ru]. Licensed under GNU GPL v3. echo/ set Connection=%1 if not defined Connection ( echo Syntax: echo %~nx0 ^<net_connection^> exit /b -1 ) set "Connection=%Connection:"=%" setlocal enabledelayedexpansion echo Checking '!Connection!' state... endlocal set Ct=2 :TmpFile set TmpFile="%Temp%\%~n0%random%.txt" if exist %TmpFile% goto TmpFile >%TmpFile% ipconfig /all for /f "tokens=1,2*" %%A in ('type %TmpFile%^|findstr /n ".*"') do ( for /f "delims=:" %%D in ("%%C") do if "%Connection%" == "%%D" goto endloop1 set /a Ct+=1 ) color 00 :endloop1 if errorlevel 1 ( echo Not found! exit /b 2 ) for /f "skip=%Ct% tokens=1 delims=." %%A in ('type %TmpFile%') do ( for /f "tokens=*" %%B in ("%%A") do ( if "%String% " == "%%B" ( echo Disconnected! color 00 ) else ( echo Connected! ) ) goto endloop2 ) :endloop2 ( del %TmpFile% exit /b %errorlevel% ) |
| Всего записей: 4000 | Зарегистр. 18-04-2005 | Отправлено: 03:13 24-01-2016 | Исправлено: GCRaistlin, 03:15 24-01-2016 |
|