Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


RE: Pull information from a file based on search criteria

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,40341
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> RE: Pull information from a file based on search criteria
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: <<   < prev  1 2 [3] 4 5   next >   >>
Login
Message << Older Topic   Newer Topic >>
 RE: Pull information from a file based on search criteria - 12/7/2006 3:05:35 AM   
  aburt

 

Posts: 104
Score: 0
Joined: 12/4/2006
Status: offline
1) The code that you are running.

' ############################################################################
''# netshrun.vbs : run netsh for a list of IPs
' [ If you start a new project, first try to describe the purpose (task) of the
'   script in one short sentence; I don't know enough about DHCP and its use
'   and about your environment to do this properly, so update the second line.
'   If you can't just implement the purpose, start with a script that makes it
'   easy to work/experiment with the different sub parts of your main problem.
' ]
' ============================================================================
' (c) 2006 by YourCompany, Inc.
'     77 YourStreet YourTown Whatever
'     T: (+49) 123 45 67 89 * E: YourName@YourCompany.com
' ============================================================================
''# usage: cscript netshrun.vbs <action>
''#  <action> : frstest   - just show the 'call a func' part works
''#             sectest   - just show the 'call a func' part really works
''#             bldCmd1   - first try to build netsh command
''#             testCmd   - building netsh command from hardcoded params and .Run
''#             parseDHCP - parse DHCP output file into dictionary
''#             cmdFound  - netsh cmd for found IPs
' [ update this usage as you add more experimental functions ]
''# usage: cscript netshrun.vbs ???
' [ update this usage when erverything works as it should; for now we can't,
'   because the main problem isn't solved yet.
' ]
' ############################################################################

Option Explicit

' ############################################################################
''# global vars
' [ will grow as we proceed ]
' ############################################################################

Dim gsCmd : gsCmd = _
   "netsh dhcp server \\<ServerName> scope <ScopeID> add reservedip <ReservedIP> <MAC_Address> <ClientName> <ClientComment>"
Dim gdicDefParms : Set gdicDefParms = CreateObject( "Scripting.Dictionary" )
Dim gsDelim : gsDelim = "ClientInfo : " & vbCrLf ' remember, remember the problem of trailing blanks!
' ############################################################################
''# main - calls experimental func specified as first param on the command
' #        or - the now still empty - 'doTheRealWork' func
' ############################################################################

WScript.Quit doMain()

Function doMain()
  Dim nRVal : nRVal = 0 ' assume all is well
  Dim sFunc : sFunc = "doTheRealWork"
' ----------  init -----------
  gdicDefParms( "<ServerName>"    ) = "Server"         ' taken from aburt's postings,
  gdicDefParms( "<ScopeID>"       ) = "100.10.12.1"     ' check carefully! I'm still
  gdicDefParms( "<ReservedIP>"    ) = "100.10.9.189"   ' afraid we need *different*
  gdicDefParms( "<MAC_Address>"   ) = "000000000000"   ' params for the missing IPs
  gdicDefParms( "<ClientName>"    ) = "Machine Name"   ' ???
  gdicDefParms( "<ClientComment>" ) = "nocomment"      ' ???
' ----------  args -----------
  If 1 <= WScript.Arguments.Count Then sFunc = WSCript.Arguments( 0 )
' ----------  func -----------
  Select Case LCase( sFunc )
     Case "frstest"
       nRVal = frsTest()
     Case "sectest"
       nRVal = secTest()
     Case "bldcmd1"
       nRVal = bldCmd1()
     Case "testcmd"
       nRVal = testCmd()
     Case "parsedhcp"
       nRVal = parseDHCP()
     Case "cmdfound"
       nRVal = cmdFound()
     Case "dotherealwork"
       nRVal = doTheRealWork()
  End Select
' ----------  term -----------
  doMain = nRVal
End Function

' ############################################################################
''# frsTest - just show the 'call a func' part works
' ############################################################################

Function frsTest()
  Dim nRVal : nRVal = 1 ' assume bad
  WScript.Echo "ok, frsTest() was called."
  frsTest = nRVal
End Function

' ############################################################################
''# secTest - just show the 'call a func' part really works
' ############################################################################

Function secTest()
  Dim nRVal : nRVal = 1 ' assume bad
  WScript.Echo "ok, secTest() was called."
  secTest = nRVal
End Function

' ############################################################################
''# bldCmd1 - first try to build netsh command
' ############################################################################

Function bldCmd1()
  Dim nRVal : nRVal = 1 ' assume bad
  WScript.Echo "ok, bldCmd1() was called."
  bldCmd1 = nRVal
End Function

Function bldCmd1()
  Dim nRVal : nRVal = 0 ' assume ok
' Start with the command containing place holders; use copy/paste if possible
  Dim sCmd  : sCmd = _
   "netsh dhcp server \\<ServerName> scope <ScopeID> add reservedip <ReservedIP> <MAC_Address> <ClientName> <ClientComment>"
' Show what we have
  WScript.Echo "sCmd:", "|" + sCmd + "|"
' Get the place holder into an array:
  Dim aNames : aNames = cutRE00( "(<\w+>)", sCmd )
' Show what we have
  WScript.Echo "aNames: (", Join( aNames, ", " ), ")"
' setup dictionary from aNames
  Dim dicParms : Set dicParms = CreateObject( "Scripting.Dictionary" )
  Dim sKey
  For Each sKey In aNames
      dicParms( sKey ) = StrReverse( sKey ) ' just for testing
  Next
' Show what we have
  For Each sKey In dicParms.Keys
      WScript.Echo sKey, "=>", dicParms( sKey )
  Next
' Apply dicParms to sCmd and prove applyRpl
  WScript.Echo "sCmd:", "|" + sCmd + "|"
  WScript.Echo "sCmd:", "|" + applyRpl( dicParms, sCmd )  + "|"
' for the lazy programmer: build an assignment block for dicParms
  For Each sKey In dicParms.Keys
      WScript.Echo "dicParms( """ + sKey + """ ) = """" "
  Next

  bldCmd1 = nRVal
End Function

' ############################################################################
''# testCmd - building netsh command from hardcoded params and .Run
' ############################################################################

Function testCmd()
  Dim nRVal : nRVal = 1 ' assume bad
  WScript.Echo "ok, testCmd() was called."
  testCmd = nRVal
End Function

Function testCmd()
  Dim nRVal : nRVal = 0 ' assume ok
  WScript.Echo "ok, testCmd() was called."
  WScript.Echo "Using gdicDefParms"

  Dim sCmd
  Dim sRet
  sCmd = applyRpl( gdicDefParms, gsCmd )
  sRet = runCmd( sCmd )
  If "" = sRet Then
     WScript.Echo "ok"
  Else
     WScript.Echo "error"
     WScript.Echo sRet
  End If

  WScript.Echo "Using dicParms"
  Dim dicParms : Set dicParms = CreateObject( "Scripting.Dictionary" )
  dicParms( "<ServerName>" ) = "your"
  dicParms( "<ScopeID>" ) = "suitable"
  dicParms( "<ReservedIP>" ) = "test"
  dicParms( "<MAC_Address>" ) = "values"
  dicParms( "<ClientName>" ) = "here"
  dicParms( "<ClientComment>" ) = "please"
  sCmd = applyRpl( dicParms, gsCmd )
  sRet = runCmd( sCmd )

  testCmd = nRVal
End Function

' ############################################################################
''# parseDHCP - parse DHCP output file into dictionary
' ############################################################################

Function parseDHCP()
  Dim nRVal : nRVal = 1 ' assume bad
  WScript.Echo "ok, parseDHCP() was called."
  parseDHCP = nRVal
End Function

Function parseDHCP()
  Dim nRVal : nRVal = 1 ' assume bad
  WScript.Echo "ok, parseDHCP() was called."

  Dim oFSO        : Set oFSO    = CreateObject("Scripting.FileSystemObject")
  Dim strDHCPFile : strDHCPFile = "d:\DHCPOuts.txt"
  'Dim sDelim      : sDelim      = "ClientInfo :" & VbCrLf ' maybe: "ClientInfo : " (trailing blank)
  Dim arrEntries, nIdx

  arrEntries = Split( oFSO.OpenTextFile( strDHCPFile ).ReadAll(), gsDelim )
' Skip header!
  For nIdx = 1 To UBound( arrEntries )
'     The entry is still just a block of text so break it into lines for processing
      Dim arrLines : arrLines = Split( arrEntries( nIdx ), vbCrLf )
      WScript.Echo arrLines( 0 )
  Next

  parseDHCP = nRVal
End Function

Function parseDHCP()
  Dim nRVal : nRVal = 1 ' assume bad
  WScript.Echo "ok, parseDHCP() was called."

  Dim dicClients  : Set dicClients = CreateObject( "Scripting.Dictionary" )
  Dim oFSO        : Set oFSO       = CreateObject( "Scripting.FileSystemObject" )
  Dim strDHCPFile : strDHCPFile    = "d:\DHCPOuts.txt"
  'Dim sDelim      : sDelim         = vbCrLf + "ClientInfo :" & vbCrLf ' maybe: "ClientInfo : " (trailing blank)
  Dim bVerbose    : bVerbose       = True ' set to False for big strDHCPFile
  Dim arrEntries, nIdx

  arrEntries = Split( oFSO.OpenTextFile( strDHCPFile ).ReadAll(), gsDelim )
' Skip header!
  For nIdx = 1 To UBound( arrEntries )
'     The entry is still just a block of text so break it into lines for processing
      Dim arrLines : arrLines = Split( arrEntries( nIdx ), vbCrLf )
      WScript.Echo arrLines( 0 )
      Dim dicTemp : Set dicTemp = CreateObject( "Scripting.Dictionary" )
      Dim strLine
      For Each strLine In arrLines
'         Clean up
          strLine = Trim( strLine )
          If "" < strLine Then
             If "." = Right( strLine, 1 ) Then strLine = Left( strLine, Len( strLine ) - 1 )
'            Split each line into a parameter and a value and add those to a temporary dictionary
             Dim arrParts : arrParts = Split( strLine, " = ")
             If 1 = UBound( arrParts ) Then
                dicTemp.Add Trim( arrParts( 0 ) ), Trim( arrParts( 1 ) )
             Else
                WScript.Echo "??? |" + strLine + "|"
             End If
          Else
'            no need to process empty lines
          End If
      Next
'     Now add that entry to the client dictionary with the IP address as the key
      Dim sIP : sIP = dicTemp( "IP Address" )
      WScript.Echo "Handling IP: |" + sIP + "|"
      If dicTemp.Exists( "IP Address" ) Then
         If dicClients.Exists( sIP ) Then
            WScript.Echo "??? - double IP: " + sIP
         Else
            dicClients.Add sIP, dicTemp
         End If
      Else
         WScript.Echo "??? - no IP Address found."
      End If
  Next
' Now we have a dictionary of all the clients reported in the file

' Dump the info to gain confidence
  If bVerbose Then
     Dim sKeyClient, dicParams, sKeyParam
     For Each sKeyClient In dicClients
         WScript.Echo "-------------", sKeyClient, "-------------"
         Set dicParams = dicClients( sKeyClient )
         For Each sKeyParam In dicParams
             WScript.Echo "", sKeyParam, "|" + dicParams( sKeyParam ) + "|"
         Next
     Next
  End If

  parseDHCP = nRVal
End Function

' ############################################################################
''# cmdFound - netsh cmd for found IPs
' ############################################################################

Function cmdFound()
  Dim nRVal : nRVal = 1 ' assume bad
  WScript.Echo "ok, cmdFound() was called."

  Dim strDHCPFile : strDHCPFile    = "d:\DHCPOuts.txt"
  Dim dicClients  : Set dicClients = parseDHCPebgreen( strDHCPFile )

  Dim sKeyClient, dicParams
  For Each sKeyClient In dicClients
      WScript.Echo "-------------", sKeyClient, "-------------"
  Next

  cmdFound = nRVal
End Function

Function cmdFound()
  Dim nRVal : nRVal = 1 ' assume bad
  WScript.Echo "ok, cmdFound() was called."

  Dim strDHCPFile : strDHCPFile    = "d:\DHCPOuts.txt"
  Dim dicClients  : Set dicClients = parseDHCPebgreen( strDHCPFile )
' stolen from testCmd()
  Dim dicParms : Set dicParms = CreateObject( "Scripting.Dictionary" )
  Dim sCmd, sRet
  Dim sKeyClient, dicParams

  For Each sKeyClient In dicClients
      WScript.Echo "-------------", sKeyClient, "-------------"
'     copied from dox box
' IP Address |100.10.12.12|
' SubnetMask |255.255.254.0|
' Client Hardware Address |12-12-12-12-12-12|
' Name |MachineNameb.org.company.com|
' Comment |(null)|
' Type |DHCP|
' Expires |12/05/2006 08:07:58|
' Owner Host IP Address |100.10.12.11|
' Owner Host NetBios Name |Server|
' Owner Host Name |(null)|
'     stolen from testCmd()
      dicParms( "<ServerName>"    ) = dicClients( sKeyClient )( "Owner Host NetBios Name" )
      dicParms( "<ScopeID>"       ) = "?<ScopeID>?"
      dicParms( "<ReservedIP>"    ) = dicClients( sKeyClient )( "IP Address" )
      dicParms( "<MAC_Address>"   ) = dicClients( sKeyClient )( "Client Hardware Address" )
      dicParms( "<ClientName>"    ) = dicClients( sKeyClient )( "Name" )
      dicParms( "<ClientComment>" ) = ""
      sCmd = applyRpl( dicParms, gsCmd )
      sRet = runCmd( sCmd )
      WScript.Echo "-------------", sKeyClient, "-------------"
  Next
  cmdFound = nRVal
End Function

' ############################################################################
''# doTheRealWork - not known yet
' ############################################################################

Function doTheRealWork()
  Dim nRVal : nRVal = 0 ' assume ok
  WScript.Echo "ok, doTheRealWork() was called, but we aren't done yet!"
  doTheRealWork = nRVal
End Function

Function doTheRealWork()
  Dim nRVal : nRVal = 0 ' assume ok
  WScript.Echo "ok, doTheRealWork() was called, but we aren't done yet!"

' stolen from Function cmdFound()
  Dim strDHCPFile : strDHCPFile    = "d:\DHCPOuts.txt"
  Dim dicClients  : Set dicClients = parseDHCPebgreen( strDHCPFile )
  Dim dicParms    : Set dicParms   = CreateObject( "Scripting.Dictionary" )
  Dim sCmd, sRet
  Dim sKeyClient, dicParams
' first try to specify IPs to look for
  Dim aIPs        : aIPs   = Array( "10", "11", "12", "13" )
' that's my problem: sIPPfx/Scope/Netmask
  Dim sIPPfx      : sIPPfx = "100.10.12."
  Dim sIP

  For Each sIP In aIPs
      sIP = sIPPfx + sIP
      WScript.Echo "-------------", sIP, "-------------"
      If dicClients.Exists( sIP ) Then
         WScript.Echo "Found"
'        stolen from cmdFound()
         dicParms( "<ServerName>"    ) = dicClients( sIP )( "Owner Host NetBios Name" )
         dicParms( "<ScopeID>"       ) = "?<ScopeID>?"
         dicParms( "<ReservedIP>"    ) = dicClients( sIP )( "IP Address" )
         dicParms( "<MAC_Address>"   ) = dicClients( sIP )( "Client Hardware Address" )
         dicParms( "<ClientName>"    ) = dicClients( sIP )( "Name" )
         dicParms( "<ClientComment>" ) = ""
      Else
         WScript.Echo "Not Found"
         Dim sKey
         For Each sKey In gdicDefParms
             dicParms( sKey ) = gdicDefParms( sKey )
         Next
      End If
      sCmd = applyRpl( dicParms, gsCmd )
      sRet = runCmd( sCmd )
      WScript.Echo "----------------------------------------"
  Next
  doTheRealWork = nRVal
End Function

' ############################################################################
''# runCmd - WShell.Exec sCmd (just echo the command for now; use copy/paste
''#          to run the command manually; fix all errors (gsCmd, gdicDefParms);
''#          then enable actual call
' ############################################################################

Function runCmd( sCmd )
  Dim sRVal : sRVal = "" ' assume ok
  WScript.Echo "Run this from the commandline and hope for the best"
  WScript.Echo sCmd

If False Then  ' fragment of aburt's code
  Dim objShell : Set objShell = CreateObject("Wscript.Shell")
  Dim objProc  : Set objProc  = objShell.Exec(strCommand)
Do
  WScript.Sleep 100
  Loop Until objProc.Status <> 0
  If SomeError() Then sRVal = "suitable message"
End If

  runCmd = sRVal
End Function

' ############################################################################
''# cutRE00 - Q & Dirty: all matches.value into 1 dim array
' ############################################################################

Function cutRE00( sPattern, sText )
  Dim aRVal : aRVal   = Array()
  Dim oRE   : Set oRE = New RegExp
  Dim oMTS, nIdx
  oRE.Pattern = sPattern
  oRE.Global  = True
  Set oMTS = oRE.Execute( sText )
  If 0 < oMTS.Count Then
     ReDim aRVal( oMTS.Count - 1 )
     For nIdx = 0 To UBound( aRVal )
         aRVal( nIdx ) = oMTS( nIdx ).Value
     Next
  End If
  cutRE00 = aRVal
End Function

' ############################################################################
''# applyRpl - replace placeholders in sText with values from dicParms
' ############################################################################

Function applyRpl( dicParms, ByVal sText )
  Dim sKey
  For Each sKey In dicParms
      sText = Replace( sText, sKey, dicParms( sKey ) )
  Next
  applyRpl = sText
End Function

' ############################################################################
''# parseDHCPebgreen - parse strDHCPFile into a dictionary
' ############################################################################

Function parseDHCPebgreen( strDHCPFile )
  Dim dicClients  : Set dicClients = CreateObject( "Scripting.Dictionary" )
  Dim oFSO        : Set oFSO       = CreateObject( "Scripting.FileSystemObject" )
  'Dim sDelim      : sDelim         = vbCrLf + "ClientInfo :" & vbCrLf ' maybe: "ClientInfo : " (trailing blank)
  Dim arrEntries, nIdx

  arrEntries = Split( oFSO.OpenTextFile( strDHCPFile ).ReadAll(), gsDelim )
' Skip header!
  For nIdx = 1 To UBound( arrEntries )
'     The entry is still just a block of text so break it into lines for processing
      Dim arrLines : arrLines = Split( arrEntries( nIdx ), vbCrLf )
      Dim dicTemp : Set dicTemp = CreateObject( "Scripting.Dictionary" )
      Dim strLine
      For Each strLine In arrLines
'         Clean up
          strLine = Trim( strLine )
          If "" < strLine Then
             If "." = Right( strLine, 1 ) Then strLine = Left( strLine, Len( strLine ) - 1 )
'            Split each line into a parameter and a value and add those to a temporary dictionary
             Dim arrParts : arrParts = Split( strLine, " = ")
             If 1 = UBound( arrParts ) Then
                dicTemp.Add Trim( arrParts( 0 ) ), Trim( arrParts( 1 ) )
             Else
'               Add (better) error handling here
                Err.Raise 4711, "??? |" + strLine + "|"
             End If
          Else
'            no need to process empty lines
          End If
      Next
'     Now add that entry to the client dictionary with the IP address as the key
      Dim sIP : sIP = dicTemp( "IP Address" )
      If dicTemp.Exists( "IP Address" ) Then
         If dicClients.Exists( sIP ) Then
'           Add (better) error handling here
            Err.Raise 4711, "??? - double IP: " + sIP
         Else
            dicClients.Add sIP, dicTemp
         End If
      Else
'        Add (better) error handling here
         Err.Raise 4711, "??? - no IP Address found."
      End If
  Next
' Now we have a dictionary of all the clients reported in the file
' return this to caller; remember the Set!!
  Set parseDHCPebgreen = dicClients
End Function

2) The command that you run.

cscript netshrun.vbs parsedhcp

3) The result that you get
 
ok, parseDHCP() was called.

4) The data file being used.
 
 This is the sample text DHCPouts.txt
 
DHCP Server version 5.6 
Num Client info read = 273. 
Total Client count = 273. 
ClientInfo : 
IP Address = 100.10.12.11.
SubnetMask = 255.255.254.0.
Client Hardware Address = 00-11-43-13-1f-f6.
Name = DT-82429.company.org.
Comment = (null).
Type = DHCP
Expires = 12/05/2006 08:07:58.
Owner Host IP Address = 100.10.9.1.
Owner Host NetBios Name = DHCPServer.
Owner Host Name = (null).
ClientInfo : 
IP Address = 100.10.12.12.
SubnetMask = 255.255.254.0.
Client Hardware Address = 00-0b-db-cb-b1-d9.
Name = dt-81214.company.org.
Comment = (null).
Type = DHCP
Expires = 12/02/2006 10:51:13.
Owner Host IP Address = 100.10.9.4.
Owner Host NetBios Name = DHCPServer.
Owner Host Name = (null).

(in reply to ebgreen)
 
 
Post #: 41
 
 RE: Pull information from a file based on search criteria - 12/7/2006 3:16:16 AM   
  ehvbs

 

Posts: 2114
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi ebgreen,

I would appreciate your help (that goes without saying)

Hi aburt,

don't despair; the problem may be trivial (but nasty). I *think*
your file has vbLf (unix) instaed of vbCrLf (dos) line endings.
can you check this?

(in reply to aburt)
 
 
Post #: 42
 
 RE: Pull information from a file based on search criteria - 12/7/2006 3:53:57 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
Ok, so here is the parseDHCP() function that should be executing:
(Ehvbs, you are much better at teaching vbscript than I am and I understand how the multiple implementations of functions came to be, but at this point I think the distraction outweighs their benefits. )

      

You should be getting considerably more output from that than just one line. If you add the lines in red below, do you get more?

arrEntries = Split( oFSO.OpenTextFile( strDHCPFile ).ReadAll(), gsDelim )
WScript.Echo "COUNT: " & UBound(arrEntries)
WScript.Echo arrEntries(0)

' Skip header!
  For nIdx = 1 To UBound( arrEntries )

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to ehvbs)
 
 
Post #: 43
 
 RE: Pull information from a file based on search criteria - 12/7/2006 4:48:53 AM   
  aburt

 

Posts: 104
Score: 0
Joined: 12/4/2006
Status: offline
I replaced the parsedhcp function() I get a compilation error 209,5

(in reply to ebgreen)
 
 
Post #: 44
 
 RE: Pull information from a file based on search criteria - 12/7/2006 5:09:29 AM   
  ehvbs

 

Posts: 2114
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi aburt,

any update on the line ending problem?

(in reply to aburt)
 
 
Post #: 45
 
 RE: Pull information from a file based on search criteria - 12/7/2006 5:22:34 AM   
  aburt

 

Posts: 104
Score: 0
Joined: 12/4/2006
Status: offline
No vbLF throughout my code anywhere.

I commented out the If and Next at the beginning of and of th parsedhcp function and if I run the entire script with Echo statements that ebgreen gave me

The output gives me The contents

ok, doTheRealWork() was called, but we aren't done yet!
COUNT: 0
DHCP Server version 5.6 
Num Client info read = 273. 
Total Client count = 273. 
ClientInfo : 
IP Address = 100.10.12.11.
SubnetMask = 255.255.254.0.
Client Hardware Address = 00-11-43-13-1f-f6.
Name = DT-82429.ds.dss.mil.
Comment = (null).
Type = DHCP
Expires = 12/05/2006 08:07:58.
Owner Host IP Address = 100.10.9.1.
Owner Host NetBios Name = BPFS03.
Owner Host Name = (null).
ClientInfo : 
IP Address = 100.10.12.12.
SubnetMask = 255.255.254.0.
Client Hardware Address = 00-0b-db-cb-b1-d9.
Name = dt-81214.ds.dss.mil.
Comment = (null).
Type = DHCP
Expires = 12/02/2006 10:51:13.
Owner Host IP Address = 100.10.9.4.
Owner Host NetBios Name = BPFS03.
Owner Host Name = (null).

------------- 100.10.12.10 -------------
Not Found
Run this from the commandline and hope for the best
netsh dhcp server \\Server scope 0.0.0.0 add reservedip 0.0.0.0 000000000000 Machine Name nocomment
----------------------------------------
------------- 100.10.12.11 -------------
Not Found
Run this from the commandline and hope for the best
netsh dhcp server \\Server scope 0.0.0.0 add reservedip 0.0.0.0 000000000000 Machine Name nocomment
----------------------------------------
------------- 100.10.12.12 -------------
Not Found
Run this from the commandline and hope for the best
netsh dhcp server \\Server scope 0.0.0.0 add reservedip 0.0.0.0 000000000000 Machine Name nocomment
----------------------------------------
------------- 100.10.12.13 -------------
Not Found
Run this from the commandline and hope for the best
netsh dhcp server \\Server scope 0.0.0.0 add reservedip 0.0.0.0 000000000000 Machine Name nocomment
----------------------------------------
Exit code: 0 , 0000h

(in reply to ehvbs)
 
 
Post #: 46
 
 RE: Pull information from a file based on search criteria - 12/7/2006 5:36:29 AM   
  ehvbs

 

Posts: 2114
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi aburt,

This:

  ok, doTheRealWork() was called, but we aren't done yet!
  COUNT: 0

together with this

  arrEntries = Split( oFSO.OpenTextFile( strDHCPFile ).ReadAll(), gsDelim )
  WScript.Echo "COUNT: " & UBound(arrEntries)

proves, that the Split() function didn't cut the content of the file into ClientInfo parts.
The only explanation I can come up with is: the script assumes vbCrLf line endings,
but your file contains either LF (unix) of CR (apple) but *not* CrLf.

A quick & dirty tests:
    do global replace "vbCrLf" => "vbLf" in a copy of netshrun.vbs

                  

 

(in reply to aburt)
 
 
Post #: 47
 
 RE: Pull information from a file based on search criteria - 12/7/2006 5:59:04 AM   
  aburt

 

Posts: 104
Score: 0
Joined: 12/4/2006
Status: offline
If I replace all VbCRLF in the script with vbLf 

and add this line WScript.Echo "COUNT: " & UBound(arrEntries)

below this line arrEntries = Split( oFSO.OpenTextFile( strDHCPFile ).ReadAll(), gsDelim ) 
 
this is the out put I get (If I run the entire script)

ok, doTheRealWork() was called, but we aren't done yet!
COUNT: 0
------------- 100.10.12.10 -------------
Not Found
Run this from the commandline and hope for the best
netsh dhcp server \\Server scope 0.0.0.0 add reservedip 0.0.0.0 000000000000 Machine Name nocomment
----------------------------------------
------------- 100.10.12.11 -------------
Not Found
Run this from the commandline and hope for the best
netsh dhcp server \\Server scope 0.0.0.0 add reservedip 0.0.0.0 000000000000 Machine Name nocomment
----------------------------------------
------------- 100.10.12.12 -------------
Not Found
Run this from the commandline and hope for the best
netsh dhcp server \\Server scope 0.0.0.0 add reservedip 0.0.0.0 000000000000 Machine Name nocomment
----------------------------------------
------------- 100.10.12.13 -------------
Not Found
Run this from the commandline and hope for the best
netsh dhcp server \\Server scope 0.0.0.0 add reservedip 0.0.0.0 000000000000 Machine Name nocomment
----------------------------------------
Exit code: 0 , 0000h


I only get this if I comment out the IF an next at the beginning and end of the function. 

'If
'     The entry is still just a block of text so break it into lines for processing

'Next
' Now we have a dictionary of all the clients reported in the file


Can you tell me why that is not working?

(in reply to ehvbs)
 
 
Post #: 48
 
 RE: Pull information from a file based on search criteria - 12/7/2006 6:20:32 AM   
  ehvbs

 

Posts: 2114
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi aburt,

can you run this stand alone script and post the output?


      

(in reply to aburt)
 
 
Post #: 49
 
 RE: Pull information from a file based on search criteria - 12/7/2006 6:33:50 AM   
  aburt

 

Posts: 104
Score: 0
Joined: 12/4/2006
Status: offline
Got 727  chars form d:\dhcpoutsam.txt
Found |ClientInfo| at Pos 85
75 20 .
76 3D =
77 20 .
78 32 2
79 37 7
80 33 3
81 2E .
82 09 .
83 0D .
84 0A .
85 43 C
86 6C l
87 69 i
88 65 e
89 6E n
90 74 t
91 49 I
92 6E n
93 66 f
94 6F o
95 20 .
96 3A :
97 09 .
98 0D .
99 0A .
100 09 .
101 49 I
102 50 P
103 20 .
104 41 A
105 64 d
Exit code: 0 , 0000h

(in reply to ehvbs)
 
 
Post #: 50
 
 RE: Pull information from a file based on search criteria - 12/7/2006 6:39:31 AM   
  ehvbs

 

Posts: 2114
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi aburt:

97 09 .

That's a tab, not a blank (I was wrong again, I'm very sorry).

Dim gsDelim : gsDelim = "ClientInfo :" & vbCrLf ' remember, remember the problem of trailing blanks!
==>
Dim gsDelim : gsDelim = "ClientInfo :" & vbTab & vbCrLf ' remember, remember the problem of trailing blanks!

(in reply to aburt)
 
 
Post #: 51
 
 RE: Pull information from a file based on search criteria - 12/7/2006 6:48:55 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
I didn't see the tab before either. 

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to ehvbs)
 
 
Post #: 52
 
 RE: Pull information from a file based on search criteria - 12/7/2006 6:54:33 AM   
  ehvbs

 

Posts: 2114
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
That's the nastiness of Tabs: you can't see them!. But I should have known better;
"blanks, line endings, tabs" should be a check list in a programmer's brain. My english
dictionary doesn't contain the words to describe my shame!

(in reply to ebgreen)
 
 
Post #: 53
 
 RE: Pull information from a file based on search criteria - 12/7/2006 7:01:37 AM   
  aburt

 

Posts: 104
Score: 0
Joined: 12/4/2006
Status: offline
I added Dim gsDelim : gsDelim = "ClientInfo :" & vbTab & vbCrLf ' remember, remember the problem of trailing blanks! to the global section and deleted 'Dim gsDelim : gsDelim = "ClientInfo : " & VbLf ' remember, remember the problem of trailing blanks!
 
if I run the entire script through I get
 
ok, doTheRealWork() was called, but we aren't done yet!
COUNT: 2
D:\IPAddress List\netshrun.vbs(459, 18) ??? | |: Unknown runtime error
 
If I run the parsedhcp funtion from the command prompt

d:\cscript netshrun.vbs parsedhcp
 
OUTPUT
 
ok, parseDHCP() was called.
D:\IPAddress List\netshrun.vbs(213, 21) Microsoft VBScript runtime error: Type m
ismatch: 'arrEntries'

(in reply to ebgreen)
 
 
Post #: 54
 
 RE: Pull information from a file based on search criteria - 12/7/2006 7:19:36 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
Which line is line 213 for you?

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to aburt)
 
 
Post #: 55
 
 RE: Pull information from a file based on search criteria - 12/7/2006 7:25:02 AM   
  aburt

 

Posts: 104
Score: 0
Joined: 12/4/2006
Status: offline
     Dim arrLines : arrLines = Split( arrEntries( nIdx ), vbLf )

(in reply to ebgreen)
 
 
Post #: 56
 
 RE: Pull information from a file based on search criteria - 12/7/2006 7:25:06 AM   
  aburt

 

Posts: 104
Score: 0
Joined: 12/4/2006
Status: offline
     Dim arrLines : arrLines = Split( arrEntries( nIdx ), vbLf )

(in reply to ebgreen)