Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
parsing interface list from netshell
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Petr Laznovsky  
View profile  
 More options Nov 18 2009, 10:42 pm
Newsgroups: microsoft.public.windows.server.scripting
From: Petr Laznovsky <nob...@nowhere.com>
Date: Wed, 18 Nov 2009 23:42:59 +0100
Local: Wed, Nov 18 2009 10:42 pm
Subject: parsing interface list from netshell

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


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Pegasus [MVP]  
View profile  
 More options Nov 18 2009, 11:18 pm
Newsgroups: microsoft.public.windows.server.scripting
From: "Pegasus [MVP]" <n...@microsoft.com>
Date: Thu, 19 Nov 2009 00:18:47 +0100
Local: Wed, Nov 18 2009 11:18 pm
Subject: Re: parsing interface list from netshell

"Petr Laznovsky" <nob...@nowhere.com> wrote in message

news:%23P6i%23BKaKHA.2188@TK2MSFTNGP04.phx.gbl...

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, 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.

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!
)


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Petr Laznovsky  
View profile  
 More options Nov 19 2009, 11:43 am
Newsgroups: microsoft.public.windows.server.scripting
From: Petr Laznovsky <nob...@nowhere.com>
Date: Thu, 19 Nov 2009 12:43:30 +0100
Local: Thurs, Nov 19 2009 11:43 am
Subject: Re: parsing interface list from netshell

Pegasus [MVP] napsal(a):

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


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tom Lavedas  
View profile  
 More options Nov 19 2009, 3:28 pm
Newsgroups: microsoft.public.windows.server.scripting
From: Tom Lavedas <tglba...@cox.net>
Date: Thu, 19 Nov 2009 07:28:36 -0800 (PST)
Local: Thurs, Nov 19 2009 3:28 pm
Subject: Re: parsing interface list from netshell
On Nov 19, 6:43 am, Petr Laznovsky <nob...@nowhere.com> wrote:

{snip}

Here is a way to get the lines parsed the way you want.  What you do
with it, is up to you ...

 @echo off
  setlocal enabledelayedexpansion
  for /f "skip=2 delims=-" %%a in (
    'type test.txt'
  ) do (
    set _tmp=%%a
    set _tmp=!_tmp:  =$!
    for /f "tokens=1-3 delims=$" %%B in (
      'echo.!_tmp!'
    ) do (
      if not "%%B"==" " echo 1:%%B  2:%%C   3:%%D
    )
  )

where the test file is exactly what you posted above.  That could be
replaced with your netsh statement (between the single quote marks).
Each line of the output would be parsed and displayed in the last ECHO
statement as FOR variables %%B, %%C and %%D.  These variables ARE case
sensitive.  The dollar sign is an arbitrary character assumed to never
appear in the text to be parsed.  Replace it with another, if there is
a problem with it (two places).

Hope that helps,
_____________________
Tom Lavedas


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2010 Google