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/5/2006 9:31:28 AM   
  aburt

 

Posts: 104
Score: 0
Joined: 12/4/2006
Status: offline
Sordoff,
I am trying to create dhcp reservation for all machines on our network.  However if you query the DHCP Server it is only giving me list of machines that are currently connected.(incomplete) So you willl get a text file that will just skip over the ips that are currently not in use.


So I was trying to create a script that would loop through all the available IP's 0 to 255.  If the IP does not exist on DHCP Server text file then create a specialized entry.

I want to execute the Netsh command (Create Reservations) for all the IPs in the range I provide 0-255. But I want the script to pull the Reserved IP address and the MAC address and client name from the from the text file.


....Will the netsh commands for *10 and *.13 the same? If not - how would you like to specify
         the different params  No I want it to pull the data required from the text file.

PULL THE DATA FROM THE TEXT FILE FOR NETSH COMMAND

strScope = "100.10.9.0"
strReservedIP = "100.10.9.10"
strMAC = "000000000010"
strClientName = "Machine Name10"
strServer = "DHCP Server" ' leave blank for local server

strScope = "100.10.9.0"
strReservedIP = "100.10.9.13"
strMAC = "000000000013"
strClientName = "Machine Name13"
strServer = "DHCP Server" ' leave blank for local server

For IP 100.10.9.14  I want to netsh to enter this (tHIS WOULD BE AN ENTRY NOT IN THE TEXT FILE BUT IP WOULD BE IN THE RANGE.

strScope = "100.10.9.0"
strReservedIP = "100.10.9.14"
strMAC = "000000000000"
strClientName = "Machine NameUnknown"
strServer = "DHCP Server" ' leave blank for local server


Hopefully you can help me.

(in reply to ehvbs)
 
 
Post #: 21
 
 RE: Pull information from a file based on search criteria - 12/5/2006 9:34:09 AM   
  ehvbs

 

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

There are two possible problems with your (excellent) script:

    (a) you split on "ClientInfo : " (tailing blank); that failed for my sample file (no tailing blank);
         aburt should check his data

    (b) you search for "100.10.9." + i  but the sample contains "100.10.12.*"

(just to eliminate needless problems)

(in reply to ehvbs)
 
 
Post #: 22
 
 RE: Pull information from a file based on search criteria - 12/5/2006 10:03:42 AM   
  ehvbs

 

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

given this sample:


      

(note: *.11 and *.12 are connected/known; *.10 and *.13 can't be found)

what do you think of this output:


      

(I'm still at lost concerning the exact params for different ips not found)

(in reply to ehvbs)
 
 
Post #: 23
 
 RE: Pull information from a file based on search criteria - 12/5/2006 11:47:49 AM   
  aburt

 

Posts: 104
Score: 0
Joined: 12/4/2006
Status: offline
ehvbs,

you got exactly what I am trying to do just at a loss on how to make it happen.

(in reply to ehvbs)
 
 
Post #: 24
 
 RE: Pull information from a file based on search criteria - 12/5/2006 10:32:11 PM   
  ehvbs

 

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

one way to make it happen: start with this script netshrun.vbs


      

Now take the main problem "run netsh for a list of IPs" and split it into two
subproblems:

   (a) building the netsh command from suitable parameters

   (b) getting these parameters (from your dhcpouts.txt file)

Concentrate on (a). Your netsh command setup:


      

What about "strClientComment"? Let's assume you need it. Concatenating complex
strings like command lines is a bad idea; especially if you have to add quotes
and other special chars. An easier and more general way is to use replacement.
So add:

   (1) ''#             bldCmd1 - first try to build netsh command

   (2)      Case "bldcmd1"
               nRVal = bldCmd1()

   (3) ' ############################################################################
       ''# 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

and run:

    cscript netshrun.vbs bldCmd1
    ok, bldCmd1() was called.

Taking advantage of the fact that the last version of a sequence of Subs/Functions
with the same name and parameter list 'wins', we can either put an enhanced version
of bldCmd1() in the script or - in a more orderly fashion - setup our embellished
function as bldCmd2(). Ok, I'm in a hurry:


      

Of course we need the functions used in bldCmd1():


      

Output:


      

For the next step, we make dicParms (now called gdicDefParms) with suitable values
and sCmd (=> gsCmd) globally available. Furthermore we add a testCmd() func to make
sure we can do the main job if get the params right.

I post the whole (current version of the) script


      

Now for the second problem:

   getting these parameters (from your dhcpouts.txt file)

Start with a simple version of the parseDHCP() function:

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

Check output:

    cscript netshrun.vbs parsedhcp
    ok, parseDHCP() was called.

Use - a slightly modified version of - ebgreen's code to work thru
".\dhcpouts.txt". First simple version:


      

Version with dictionary:


      

Now copy the code of parseDHCP() to an independent function to make it
reusable:


      

I admit a bit of editing was necessary. To test it, add a first version
of cmdFound:

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

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

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

  cmdFound = nRVal
End Function

--- output ----------
ok, cmdFound() was called.
------------- 100.10.12.11 -------------
------------- 100.10.12.12 -------------

--- output after changing 100.10.12.12 to 100.10.12.11 in DHCPOuts.txt -----------
cscript netshrun.vbs cmdFound
ok, cmdFound() was called.
C:\wis\_vbs\0506\dev\forum\netshrun.vbs(448, 13) ??? - double IP: 100.10.12.11: Unbekannter Laufzeitfehler
[/code]

Next version of cmdFound() with mapping of dicClients to dicParams:


      

Puh, last lap! Let's risk to work in doTheRealWork()! First try:


      

output with the commandline building merged:


      

And the current version of the whole script:


      

(in reply to aburt)
 
 
Post #: 25
 
 RE: Pull information from a file based on search criteria - 12/6/2006 2:39:23 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
Ehvbs, thoroughness be thy name. 


As for the two issues that you raised with my script, both issues were based on the samples posted by the op. I used his sample text which did have "Client : ", and I used his loop which looped IPs other than what was in his sample (which I pointed out to him in a later post).

_____________________________

"... 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 #: 26
 
 RE: Pull information from a file based on search criteria - 12/6/2006 3:04:39 AM   
  ehvbs

 

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

I'm grateful for your choice of words. (I expected - and deserve - pedantic; but I can't help it).
It wasn't my intention to put any blame on you; I just wanted to avoid additional problems caused
by such nearly invisible discrepancies.

ehvbs

(in reply to ebgreen)
 
 
Post #: 27
 
 RE: Pull information from a file based on search criteria - 12/6/2006 3:12:26 AM