Skip to content

Commit

Permalink
Create checkNet.bat
Browse files Browse the repository at this point in the history
  • Loading branch information
npocmaka committed Apr 25, 2015
1 parent cf9fa9c commit 89c5edd
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions network/checkNet.bat
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

0 comments on commit 89c5edd

Please sign in to comment.