-
Notifications
You must be signed in to change notification settings - Fork 865
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,51 @@ | |||
@echo off | |||
:checkNet | |||
|
|||
:: | |||
:: checks if a network interface with given name is connected | |||
:: or not through ipconfig command | |||
:: | |||
|
|||
setlocal | |||
|
|||
if "%~1" equ "" echo no network name passed & exit /b 1 | |||
|
|||
set "network_to_check=%~1" | |||
if "%network_to_check:~-1,1%" NEQ ":" set "network_to_check=%network_to_check%:" | |||
|
|||
set nt=0 | |||
setlocal enableDelayedExpansion | |||
for /f "skip=3 delims=" %%$ in ('ipconfig') do ( | |||
set "line=%%$" | |||
! echo %%$ >&2 | |||
|
|||
if "!line:~0,1!" neq " " ( | |||
set /a nt=nt+1 | |||
set _nt!nt!=!line! | |||
|
|||
) else ( | |||
! echo ---- | |||
for /f %%# in ("!nt!") do ( | |||
! echo a:%%# | |||
! echo --- %%# --- | |||
|
|||
set "_nt!nt!=!_nt%%#! !line!" | |||
|
|||
) | |||
) | |||
) | |||
|
|||
set _nt|find /i "%network_to_check%" >nul 2>nul||( | |||
echo network not found | |||
exit /b 1 | |||
) | |||
|
|||
set _nt| find /i "%network_to_check%"|find /i "Media disconnected" >nul 2>nul&&( | |||
echo disconnected | |||
exit /b 1 | |||
) | |||
|
|||
echo connected | |||
|
|||
endlocal | |||
endlocal |