Speed up reading results in batch script -


what trying do, speed reading results of batch file.

am trying different values using netsh commands , present them in script console takes long. see below small part of script idea. (this small part, i'm getting around 50 different values , using more netsh commands)

does know way speed process?

. . . netsh interface ipv4 show config %adapterlan%  >temp /f "tokens=3" %%i in ('findstr "ip address" temp') set ip=%%i echo.  ip address        : %ip%  /f "tokens=5 delims=) " %%i in ('findstr  "subnet prefix" temp')  set mask=%%i echo.  mask              : %mask%  /f "tokens=3" %%i in ('findstr  "gateway:" temp')  set gateway=%%i echo.  gateway           : %gateway%  /f "tokens=1,5,6" %%a in ('findstr  "dns" temp') set dns1=%%a&set dns5=%%b&set dns6=%%c if "%dns1%"=="statically" set dns=%dns5% if "%dns1%"=="dns"        set dns=%dns6%  echo.  dns server        : %dns%  /f "tokens=3" %%i in ('findstr "gateway metric" temp') set gmetric=%%i /f "tokens=2" %%i in           ('findstr "interfacemetric" temp')   set imetric=%%i set /a metriclan=gmetric + imetric  echo.  metric            : %metriclan%  /f "tokens=3" %%i in ('find "dhcp enabled" temp') set landhcp=%%i if "%dns1%"=="statically"  set xx=static if "%dns1%"=="dns"         set xx=dhcp   if /i %landhcp%==no        set landhcp=static if /i %landhcp%==yes       set landhcp=dhcp echo.  obtained ip       : %landhcp% echo.  obtained dns      : %xx% /f "tokens=3 delims=," %%a in ('getmac /v /fo csv ^| find """%adapterlan-without-q%""" ')  set maclan=%%a echo.  mac-addres        : %maclan% del temp . . . netsh wlan show profile >temp . similar process of getting values netsh command sent them in temp file …echo 1 want on screen ..delete file etc. 

next approach bit faster (no temporary file(s), updated no multiple findstr):

@echo off >nul setlocal enableextensions enabledelayedexpansion set "adapterlan=wiredethernet" set "imetric=" set "gmetric=" /f "tokens=1,2* delims=:" %%g in ('   netsh interface ipv4 show config "%adapterlan%"^|findstr /n /r "^" ') (     rem echo g="%%g" h="%%h" i="%%i"     if "%%i"=="" (       rem line  1   skip       rem line  2 = configuration interface       rem line 10 = dns server #2 etc.     ) else (         set "hh=%%h"         set "xx=!hh:ip address=!"         if not "!hh!"=="!xx!" /f "tokens=1*" %%i in ("%%i") set "ip=%%i"          set "xx=!hh:subnet prefix=!"         if not "!hh!"=="!xx!" /f "tokens=3 delims=) " %%i in ("%%i") set "mask=%%i"          set "xx=!hh:default gateway=!"         if not "!hh!"=="!xx!" /f "tokens=1*" %%i in ("%%i") set "gateway=%%i"          set "xx=!hh:gateway metric=!"         if not "!hh!"=="!xx!" /f "tokens=1*" %%i in ("%%i") set "gmetric=%%i"          set "xx=!hh:interfacemetric=!"         if not "!hh!"=="!xx!" /f "tokens=1*" %%i in ("%%i") set "imetric=%%i"      ) ) echo(  ip address        : [%ip%] echo(  mask              : [%mask%] echo(  gateway           : [%gateway%] set /a metriclan=gmetric + imetric  echo(  metric            : [%metriclan%] endlocal goto :eof 

output:

==>d:\bat\so\31356115.bat   ip address        : [192.168.1.100]   mask              : [255.255.255.0]   gateway           : [192.168.1.1]   metric            : [20]  ==> 

edit

here approach: unlike netsh, parsing wmic command output seems bit easier when used get verb /value switch it's defined , structured. find here info netsh: next code snippet should read , make public huge range of information all enabled nic adapter(s) in defined local or remote computer:

@echo off >nul setlocal enableextensions enabledelayedexpansion set "netcount=0" set "compname=%computername%" :: local or remote computer name set "compidxs=" /f "tokens=2 delims==" %%n in ('   wmic /node:"%compname%" nic "netenabled=true" interfaceindex /value 2^>nul ^| find "=" ') /f "tokens=*" %%n in ("%%n") (   /f "tokens=*" %%g in ('     wmic /node:"%compname%" nic "interfaceindex=%%n" /value 2^>nul ^| find "="   ') /f "tokens=*" %%g in ("%%g") set "_%%n%%g"   /f "tokens=*" %%i in ('     wmic /node:"%compname%" nicconfig "interfaceindex=%%n" /value 2^>nul ^| find "="   ') /f "tokens=*" %%i in ("%%i") set "_%%n_%%i"   set /a "netcount+=1"   set "compidxs=!compidxs! "%%n"" ) set _ rem sample of it: echo compname=%compname% netcount=%netcount% compidxs=%compidxs% %%x in (%compidxs%) (   echo enabled interfaceindex=%%~x  netconnectionid=!_%%~xnetconnectionid!   /f "tokens=1,2 delims={}," %%i in ("!_%%~x_ipaddress!") echo ipv4=%%~i ipv6=%%~j   ) 

read dave benham's wmic , for /f: fix trailing <cr> problem see why wmic command output parsed via couple of nested for loops.


Comments