@echo off

set /a mynum=-1
set discf=1

:getline
set myline=
set /p myline=

rem check end of file 
if "%myline%"=="###fin###" goto fin

rem skip empty lines
if "%myline%"=="" goto getline

rem check if NIC block header 
if "%myline:~0,2%"=="  " goto chkline

rem skip initial blocks of ipconfig output
if %mynum% lss 1 goto nxtnic

rem check if NIC block finished and no disconnected status detected
if not %discf%==1 goto fin

:nxtnic
rem start next NIC block processing
set /a mynum=mynum+1
set discf=0
goto nxtline

:chkline
rem check if disconnected status
if "%myline%"=="%myline:disconnected=%" goto nxtline
set discf=1

:nxtline
rem echo %mynum%:%discf%:%myline%
goto getline

:fin
rem final NIC status check
rem echo Eth: %mynum%
if %mynum% lss 1 goto fin1
if %discf%==1 goto fin

rem save NIC number
echo>nic.ini [interface%mynum%]

:fin1
set myline=
set mynum=
set discf=
