Over the past few days I've found myself delving back into VBScript a bit, at the request of one of my co-workers. I'm by no means an expert at vbs, but I can work my way around it pretty well and accomplish most tasks.
My co-worker has a pretty mundane task that he has to perform fairly frequently, as do most of us. He's the network guru on our team and has to periodically review all of the ACL's on our routers. While reviewing them he must correlate each host IP with an asset in our asset management database or note that the host IP is not listed in the AM-DB. He came to me a few weeks ago and asked if I could script that for him, hence my recent forray back into vbs. :)
The philosophy behind the script wasn't too complex... Read the input file line-by-line, see if the current line contains the string "host IP#", if it does then query the AM-DB for the host info & insert that into the output file along with the current line, if not then just insert the current line as-is into the output file. The end result is a new ACL that has in-line comments for each host IP listed.
To demonstrate that I'm far from an expert at vbs, I'll openly admit that this is the first time I've used regular expressions in any of my scripts. But damn, if used correctly, they're freakin' cool!
So, here's a quick how2 for using RegExp in VBScript to query for an IP number in a string:
One of the hardest things to do with regular expressions, is to figure out the syntax of the Pattern you're looking for. There are a few sites that deal with nothing but figuring out regular expressions (regular-expressions.info, RegExLib.com, etc.). To help understand it a little better, let's breakdown line 6 above:
I also used RegExp to check for the correct input when starting the script. For instance, my script can only read from text files (.txt) so I added the following function to verify this before trying anything else:
Well, I hope that helps someone out there in the great big www.
A few resources:
Email or RSS 1.0, RSS 2.0 & Atom