Loading ...
Sorry, an error occurred while loading the content.
 

find a string that occurs prior to a search variable

Expand Messages
  • demodog2001
    All: I have a batch file that pings all the addresses within a specific subnet and then locates netbios names and copies same to a file. I would like to search
    Message 1 of 4 , Nov 17, 2004
      All:
      I have a batch file that pings all the addresses within a specific
      subnet and then locates netbios names and copies same to a file.
      I would like to search that file for user name and have the script
      return the netbios name of the PC.
      However, the user id occurs after the machine name, as shown below
      I would search for UserID, and have the script return WSB-Unknown
      Rgds
      S

      IntelPro1000:
      Node IpAddress: [xxx.xxx.xxx.xxx] Scope Id: []



      NetBIOS Remote Machine Name Table



      Name Type Status

      ---------------------------------------------

      WSB-Unknown <00> UNIQUE Registered

      DOMAIN <00> GROUP Registered

      WSB-Unknown <20> UNIQUE Registered

      WSB-Unknown <03> UNIQUE Registered

      WSB-Unknown$ <03> UNIQUE Registered

      Domain <1E> GROUP Registered

      UserID <03> UNIQUE Registered
    • Mic
      ... Can we clean up this file as it s being created, to make searching easy? What s the command that generates the NetBIOS Remote Machine Name Table ? Which
      Message 2 of 4 , Nov 17, 2004
        On Wed, 17 Nov 2004 15:36:46 -0000, demodog2001 wrote:

        > All:
        > I have a batch file that pings all the addresses within a specific
        > subnet and then locates netbios names and copies same to a file.

        Can we clean up this file as it's being created, to make searching easy?

        What's the command that generates the "NetBIOS Remote Machine Name Table"?

        Which instance of "WSB-Unknown" are you looking at below?

        Where is the user name and is "UserID" literal or a number etc?

        What OS are you using?

        Can you give some more real life examples?


        > I would like to search that file for user name and have the script
        > return the netbios name of the PC.
        > However, the user id occurs after the machine name, as shown below
        > I would search for UserID, and have the script return WSB-Unknown
        > Rgds
        > S
        >
        > IntelPro1000:
        > Node IpAddress: [xxx.xxx.xxx.xxx] Scope Id: []
        >
        >
        >
        > NetBIOS Remote Machine Name Table
        >
        >
        >
        > Name Type Status
        >
        > ---------------------------------------------
        >
        > WSB-Unknown <00> UNIQUE Registered
        >
        > DOMAIN <00> GROUP Registered
        >
        > WSB-Unknown <20> UNIQUE Registered
        >
        > WSB-Unknown <03> UNIQUE Registered
        >
        > WSB-Unknown$ <03> UNIQUE Registered
        >
        > Domain <1E> GROUP Registered
        >
        > UserID <03> UNIQUE Registered
        >
        >
        >

        --
        Regards,
        Mic
      • demodog2001
        I m open for suggestions as to cleaning up the output. OS is W2K, SP4. From the command line, nbtstat -a generates a single record, as in the
        Message 3 of 4 , Nov 17, 2004
          I'm open for suggestions as to cleaning up the output.
          OS is W2K, SP4.
          From the command line, nbtstat -a <ip address> generates a single
          record, as in the orignal post.
          An example username would be UserJ, or any username as it shows in
          the <03> record line.
          script follows
          tia
          S
          ---------------
          @echo off
          set host=
          set host1=
          set network=
          set firsthost=
          set lasthost=
          if exist ipfile.txt del ipfile.txt
          if exist network.txt del network.txt
          if exist netbios.txt del netbios.txt
          set /p network= What network do you want to ping (xxx.yyy.zzz)?
          :start
          set /p firsthost= Which host do you want to start with?
          set /p lasthost= Which host do you want to end with?
          if /i "%firsthost%"=="" set firsthost=10
          if /i "%lasthost%"=="" set lasthost=12
          if %network%=="" goto :bye
          echo.
          echo.
          echo.
          echo Pinging %network%.0 and generating ipfile.txt, a list of active
          hosts,
          echo and network.txt, a list of machines we're trying to resolve.
          echo along with netbios.txt, a list of Netbios names for those
          machines we found.
          echo.
          echo.

          for /l %%a in (%firsthost%,1,%lasthost%) do echo %network%.%%a &&
          ping -a %network%.%%a>>network.txt
          echo .>file2.txt
          for /f "tokens=1-9" %%a in (network.txt) do if "%%a"=="Reply"
          call :findit %%c
          goto :netbios
          :findit
          set host=%1
          set host=%host:~0,-1%
          echo %host%>>ipfile.txt
          sort <ipfile.txt >file2.txt
          set a=
          set b=
          echo.>fileout.txt
          for /f "delims=" %%a in (file2.txt) do call :next "%%a"
          set a=
          set b=
          goto :eof
          :next
          set a=%b%
          set b=%~1
          if not "%a%"=="%b%" echo %b%>>fileout.txt
          rem echo fileout contains:&& type fileout.txt
          goto :eof
          :netbios
          echo.>netbios.txt
          for /f "tokens=1-9" %%a in (fileout.txt) do echo host is %%
          a>>netbios.txt && echo.>>netbios.txt && nbtstat -A %%a>>netbios.txt
          goto :eof
          :bye
          echo O ... OK ... Well, .. Goodbye then .....
          goto :eof
          :eof
          ------------------------------------------------
          --- In batchworld@yahoogroups.com, Mic <micm@m...> wrote:
          > On Wed, 17 Nov 2004 15:36:46 -0000, demodog2001 wrote:
          >
          > > All:
          > > I have a batch file that pings all the addresses within a
          specific
          > > subnet and then locates netbios names and copies same to a file.
          >
          > Can we clean up this file as it's being created, to make searching
          easy?
          >
          > What's the command that generates the "NetBIOS Remote Machine Name
          Table"?
          >
          > Which instance of "WSB-Unknown" are you looking at below?
          >
          > Where is the user name and is "UserID" literal or a number etc?
          >
          > What OS are you using?
          >
          > Can you give some more real life examples?
          >
          >
          > > I would like to search that file for user name and have the
          script
          > > return the netbios name of the PC.
          > > However, the user id occurs after the machine name, as shown below
          > > I would search for UserID, and have the script return WSB-Unknown
          > > Rgds
          > > S
          > >
          > > IntelPro1000:
          > > Node IpAddress: [xxx.xxx.xxx.xxx] Scope Id: []
          > >
          > >
          > >
          > > NetBIOS Remote Machine Name Table
          > >
          > >
          > >
          > > Name Type Status
          > >
          > > ---------------------------------------------
          > >
          > > WSB-Unknown <00> UNIQUE Registered
          > >
          > > DOMAIN <00> GROUP Registered
          > >
          > > WSB-Unknown <20> UNIQUE Registered
          > >
          > > WSB-Unknown <03> UNIQUE Registered
          > >
          > > WSB-Unknown$ <03> UNIQUE Registered
          > >
          > > Domain <1E> GROUP Registered
          > >
          > > UserID <03> UNIQUE Registered
          > >
          > >
          > >
          >
          > --
          > Regards,
          > Mic
        • Mic
          ... echo. netbios.txt if exist flag.txt del flag.txt for /f tokens=1-9 %%a in (fileout.txt) do ( for /f tokens=1 delims= %%x in ( nbtstat -A %%a ) do (
          Message 4 of 4 , Nov 17, 2004
            On Wed, 17 Nov 2004 17:51:52 -0000, demodog2001 wrote:

            > I'm open for suggestions as to cleaning up the output.
            > OS is W2K, SP4.

            :netbios
            echo.>netbios.txt
            if exist flag.txt del flag.txt
            for /f "tokens=1-9" %%a in (fileout.txt) do (
            for /f "tokens=1 delims=<> " %%x in ('nbtstat -A %%a') do (
            if exist flag.txt echo Netbios name for host %%a is "%%x">>netbios.txt&del flag.txt
            echo.%%x|find "-----------------" 1>nul && type nul>flag.txt
            )
            )
            goto :EOF

            I tested the code above with XP and it (clumsily) detects a line containing
            "-----" etc and then take the first token on the following line, reporting it
            as follows.

            Netbios name for host 192.168.0.1 is "ALIEN"
            Netbios name for host 192.168.0.2 is "ALF"
            Netbios name for host 192.168.0.3 is "FRODO"

            I suspect there is more to your requirements - and I couldn't see any username -
            so I went with what I understood. If I misunderstood then please let me know.




            > From the command line, nbtstat -a <ip address> generates a single
            > record, as in the orignal post.
            > An example username would be UserJ, or any username as it shows in
            > the <03> record line.
            > script follows
            > tia
            > S
            > ---------------
            > @echo off
            > set host=
            > set host1=
            > set network=
            > set firsthost=
            > set lasthost=
            > if exist ipfile.txt del ipfile.txt
            > if exist network.txt del network.txt
            > if exist netbios.txt del netbios.txt
            > set /p network= What network do you want to ping (xxx.yyy.zzz)?
            >:start
            > set /p firsthost= Which host do you want to start with?
            > set /p lasthost= Which host do you want to end with?
            > if /i "%firsthost%"=="" set firsthost=10
            > if /i "%lasthost%"=="" set lasthost=12
            > if %network%=="" goto :bye
            > echo.
            > echo.
            > echo.
            > echo Pinging %network%.0 and generating ipfile.txt, a list of active
            > hosts,
            > echo and network.txt, a list of machines we're trying to resolve.
            > echo along with netbios.txt, a list of Netbios names for those
            > machines we found.
            > echo.
            > echo.
            >
            > for /l %%a in (%firsthost%,1,%lasthost%) do echo %network%.%%a &&
            > ping -a %network%.%%a>>network.txt
            > echo .>file2.txt
            > for /f "tokens=1-9" %%a in (network.txt) do if "%%a"=="Reply"
            > call :findit %%c
            > goto :netbios
            >:findit
            > set host=%1
            > set host=%host:~0,-1%
            > echo %host%>>ipfile.txt
            > sort <ipfile.txt >file2.txt
            > set a=
            > set b=
            > echo.>fileout.txt
            > for /f "delims=" %%a in (file2.txt) do call :next "%%a"
            > set a=
            > set b=
            > goto :eof
            >:next
            > set a=%b%
            > set b=%~1
            > if not "%a%"=="%b%" echo %b%>>fileout.txt
            > rem echo fileout contains:&& type fileout.txt
            > goto :eof
            >:netbios
            > echo.>netbios.txt
            > for /f "tokens=1-9" %%a in (fileout.txt) do echo host is %%
            > a>>netbios.txt && echo.>>netbios.txt && nbtstat -A %%a>>netbios.txt
            > goto :eof
            >:bye
            > echo O ... OK ... Well, .. Goodbye then .....
            > goto :eof
            >:eof
            > ------------------------------------------------
            > --- In batchworld@yahoogroups.com, Mic <micm@m...> wrote:
            >> On Wed, 17 Nov 2004 15:36:46 -0000, demodog2001 wrote:
            >>
            >>> All:
            >>> I have a batch file that pings all the addresses within a
            > specific
            >>> subnet and then locates netbios names and copies same to a file.
            >>
            >> Can we clean up this file as it's being created, to make searching
            > easy?
            >>
            >> What's the command that generates the "NetBIOS Remote Machine Name
            > Table"?
            >>
            >> Which instance of "WSB-Unknown" are you looking at below?
            >>
            >> Where is the user name and is "UserID" literal or a number etc?
            >>
            >> What OS are you using?
            >>
            >> Can you give some more real life examples?
            >>
            >>
            >>> I would like to search that file for user name and have the
            > script
            >>> return the netbios name of the PC.
            >>> However, the user id occurs after the machine name, as shown below
            >>> I would search for UserID, and have the script return WSB-Unknown
            >>> Rgds
            >>> S
            >>>
            >>> IntelPro1000:
            >>> Node IpAddress: [xxx.xxx.xxx.xxx] Scope Id: []
            >>>
            >>>
            >>>
            >>> NetBIOS Remote Machine Name Table
            >>>
            >>>
            >>>
            >>> Name Type Status
            >>>
            >>> ---------------------------------------------
            >>>
            >>> WSB-Unknown <00> UNIQUE Registered
            >>>
            >>> DOMAIN <00> GROUP Registered
            >>>
            >>> WSB-Unknown <20> UNIQUE Registered
            >>>
            >>> WSB-Unknown <03> UNIQUE Registered
            >>>
            >>> WSB-Unknown$ <03> UNIQUE Registered
            >>>
            >>> Domain <1E> GROUP Registered
            >>>
            >>> UserID <03> UNIQUE Registered
            >>>
            >>>
            >>>
            >>
            >> --
            >> Regards,
            >> Mic
            >
            >
            >
            >
            >
            >
            > To Post a message, send it to: batchworld@...
            >
            > To Unsubscribe, send a blank message to: batchworld-unsubscribe@...
            > Yahoo! Groups Links
            >
            >
            >


            --
            Regards,
            Mic
          Your message has been successfully submitted and would be delivered to recipients shortly.