Pegasus [MVP] napsal(a):
> "Petr Laznovsky" <nob
...@nowhere.com> wrote in message
>
news:%23P6i%23BKaKHA.2188@TK2MSFTNGP04.phx.gbl...
>> Hi there, I am beginner in the CMD scripting.
>> I want to get interface list, each iface into each variable. I have two
>> problems with this. My command is:
>> for /f "tokens=3,* delims= " %i in ('netsh in sh in') do echo %i %j
>> I am use local (Czech) language version of WXP and the tranlation of nesth
>> use two words for loopback ("zpetna smycka" something like "loop back"
>> with space between those two words). When I try to parse it, there is
>> problem with delimiter bacause there are two words for loopback in the
>> column "TYPE", something like this:
>> Admin State State Type Interface Name
>> -------------------------------------------------------------------------
>> Enabled Dedicated dummy
>> Enabled Dedicated Local Area Connection
>> Enabled Internal Internal
>> Enabled Loop Back Loop Back
>> Second probles is I have no idea how to push ecach line of output (name of
>> each iface) into separated variable.
>> Any ideas??
>> Petr Laznovsky
> When I run the command
> for /f "tokens=3,* delims= " %i in ('netsh in sh in') do echo %i %j
> then my console output looks radically different from yours,
The output I post is not output from full parsing command, but from
"netsh in sh in" in English OS version. I want to demonstrate the "two
words for loopback" problem. Real outpul from "netsh in sh in" is following:
Admin. stav Stav Typ Název rozhraní
-------------------------------------------------------------------------
Povoleno Vyhrazený Bluetooth Network
Povoleno Vyhrazený ETH0
Povoleno Vyhrazený WLAN0
Povoleno Vyhrazený Bezdrátové připojení k síti 4
Povoleno Vyhrazený Bezdrátové připojení k síti 2
Povoleno Vyhrazený Hamachi
Povoleno Vyhrazený Bezdrátové připojení k síti 3
Povoleno Vnitřní Vnitřní
Povoleno Zpětná smyčka Zpětná smyčka
--------------------------------------------------------------------------
Output from real FOR /F command is:
-----------------------------------------------------------
c:\>echo Stav Typ Název rozhraní
Stav Typ Název rozhraní
c:\>echo Bluetooth Network
Bluetooth Network
c:\>echo ETH0
ETH0
c:\>echo WLAN0
WLAN0
c:\>echo Bezdrátové připojení k síti 4
Bezdrátové připojení k síti 4
c:\>echo Bezdrátové připojení k síti 2
Bezdrátové připojení k síti 2
c:\>echo Hamachi
Hamachi
c:\>echo Bezdrátové připojení k síti 3
Bezdrátové připojení k síti 3
c:\>echo Vnitřní
Vnitřní
c:\>echo smyčka Zpětná smyčka
smyčka Zpětná smyčka
----------------------------------------------------------
on last line you can see: "back Loop back" instead of "Loop back" or
"Loopback"
even when
> allowing for linguistic differences. I am therefore unable to give you a
> solution that is guaranteed to work for you. And while I appreciate that the
> Czech translation of "loopback" generates two words, I do not understand
> what you're trying to extract from the console output.
I am administrator of IP network consist of many small subnets (/27 and
/29) without use of DHCP. Technicians with the laptops win WXP need time
by time connect to some subnets in some racks and need to change IP
address manually which take some time and mistakes are done frequently.
Therefor I wrote attached batch which allow him to choose location from
batch menu and batch will setup IP subsystem automatically. But there is
one issue: Setup address automatically by netsh need to provide iface
name and because on some node technicians connect through ethernet aand
on some nodes tahy need to connect throuh wireless my idea is first
provide him menu with list of network adapters present in the laptop,
let him choose adapter, than fill adapter name into variable and pass
into next part of batch (already done) which is choose
location/ip_address and setup to system.
Sorry for my poor english, hope you understood...
> The code below is an example for your second question: How to assign each
> line of the screen output to a variable. The text file d:\temp\test.txt
> contains the exact console lines that you posted in your note.
> @echo off
> SetLocal EnableDelayedExpansion
> set Line=0
> for /F "delims=" %%a in ('type "d:\temp\test.txt"') do (
> set /a Line=!Line! + 1
> set Var=%%a
> echo Line!Line!=!Var!
> )
Now I have no time, but I will try ASAP. Thank you for this...
L.
[
ipset.cmd 3K ]
::
::
:: IP set v. 1.0
:: 5.11.2009
:: la...@volny.cz
::
::
cls
@echo off
echo.
:: echo "Setup service IP for work on router:
echo Nastavit servisni IP pro praci na routeru:
echo.
echo.
echo.
echo LAZNA press L
echo.
echo CISTICZ press C
echo.
echo ZEB press Z
echo.
echo PANELAK press P
echo.
echo SONNY press S
echo.
echo TABORSKA press T
echo.
echo.
echo.
SET Choice=
:: Echo Choose proper letter and press Enter
SET /P Choice=ZVOL PRISLUSNE PISMENO A STISKNI ENTER: -^>
IF NOT '%Choice%'=='' SET Choice=%Choice%
:: /I makes the IF comparison case-insensitive
IF /I '%Choice%'=='l' GOTO :lazna
IF /I '%Choice%'=='c' GOTO :cisticz
IF /I '%Choice%'=='z' GOTO :zeb
IF /I '%Choice%'=='p' GOTO :panelak
IF /I '%Choice%'=='s' GOTO :sonny
IF /I '%Choice%'=='t' GOTO :taborska
:: Echo: Invalid option, try again..
echo VOLBA "%Choice%" NENI PLATNA. ZKUS TO ZNOVU
echo.
:lazna
cls
:: echo Setting up IP address
echo Nastavuji IP Adresu...
netsh int ip set address eth0 static 10.12.32.6 255.255.255.128 10.12.32.1 1
cls
:: echo setting up DNS servers
echo Nastavuji DNS servery...
netsh int ip set dns eth0 static 10.12.32.3
netsh int ip add dns eth0 10.12.17.1 index=2
goto END
:cisticz
cls
echo Nastavuji IP Adresu...
netsh int ip set address eth0 static 10.12.35.254 255.255.255.192 10.12.35.193 1
cls
echo Nastavuji DNS servery...
netsh int ip set dns eth0 static 10.12.32.3
netsh int ip add dns eth0 10.12.17.1 index=2
goto END
:zeb
cls
echo Nastavuji IP Adresu...
netsh int ip set address eth0 static 10.12.35.93 255.255.255.224 10.12.35.65 1
cls
echo Nastavuji DNS servery...
netsh int ip set dns eth0 static 10.12.32.3
netsh int ip add dns eth0 10.12.17.1 index=2
goto END
:panelak
cls
echo Nastavuji IP Adresu...
netsh int ip set address eth0 static 10.12.33.190 255.255.255.224 10.12.33.161 1
cls
echo Nastavuji DNS servery...
netsh int ip set dns eth0 static 10.12.32.3
netsh int ip add dns eth0 10.12.17.1 index=2
goto END
:sonny
cls
echo Nastavuji IP Adresu...
netsh int ip set address eth0 static 10.12.35.189 255.255.255.224 10.12.35.161 1
cls
echo Nastavuji DNS servery...
netsh int ip set dns eth0 static 10.12.32.3
netsh int ip add dns eth0 10.12.17.1 index=2
goto END
:taborska
cls
echo Nastavuji IP Adresu...
netsh int ip set address eth0 static 10.12.71.30 255.255.255.224 10.12.71.1 1
cls
echo Nastavuji DNS servery...
netsh int ip set dns eth0 static 10.12.32.3
netsh int ip add dns eth0 10.12.17.1 index=2
goto END
:end
EOF