I am new to VBScript. I have, say 100, IP addresses, which are divided
into
4 groups. E.g.
UNIX_GRP: 192.168.1.2 192.168.2.3 192.168.8.200 ... (20 addresses in
total)
WINDOWS_GRP: 192.168.6.9 192.168.12.13 192.168.18.20 ... (65 in total)
ROUTER_GRP: 192.168.1.1 192.168.2.1 ... (10 in total)
FIREWALL_GRP: 192.168.1.2 ... (5 in total)
Then I have a log file, which contains say 10,000 lines and each line
contains
an IP address (must in the above 100 addresses). I have to parse each
line,
get the IP address, and copy each log line into one of 4 files
depending on
which group the IP addres is in.
I am thinking to create a lookup table for these 100 ip addresses, e.g.
192.168.1.1 ROUTER_GRP
192.168.1.2 UNIX_GRP
...
So my script could easily figure out the ip address belongs to which
group.
I could do this quickly in unix shell or Perl, but I have to use
VBScript for this
project. I was wondering how to create a lookup table in VBScript, how
to
use IP-address as the array index or I have to use 2-d array. Or you
might
have suggestions to solve the problem.
Thanks in advance.
James
> Hi all,
[...]
> I am thinking to create a lookup table for these 100 ip addresses, e.g.
> 192.168.1.1 ROUTER_GRP
> 192.168.1.2 UNIX_GRP
> ...
>
> So my script could easily figure out the ip address belongs to which
> group.
> I could do this quickly in unix shell or Perl, but I have to use
> VBScript for this
[...]
Look up the Dictionary Object in the VBScript Docs and think of
it as very simple version of a Perl hash.
put the "for loops" in order of least to greatest within the readfile
loop. Hope that helps.
-J
Dim arrUnix(2)
arrUnix(0) = "192.168.1.2"
arrUnix(1) = "192.168.2.3"
arrUnix(2) = "192.168.8.200"
Dim arrWindows(2)
arrWindows(0) = "192.168.6.9"
arrWindows(1) = "192.168.12.13"
arrWindows(2) = "192.168.18.20"
Dim arrRouter(1)
arrRouter(0) = "192.168.1.1"
arrRouter(1) = "192.168.2.1"
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFile = oFSO.OpenTextFile(".\datalog.txt",1)
Set oUnixFile = oFSO.OpenTextFile(".\unixfile.txt",2,1)
'....windowsfile.txt...
'....routerfile.txt....
Do Until oFile.AtEndOfStream
iMatch = 0
sLine = oFile.ReadLine
wscript.echo sLine
For i = 0 to uBound(arrUnix)
If arrUnix(i) = sLine Then
oUnixFile.writeline sLine
iMatch = 1
End If
Next
If iMatch <> 1 Then
For i = 0 to uBound(arrwindows)
If arrWindows(i) = sLine Then
oWindowsFile.writeline sLine
iMatch = 1
End If
Next
End If
If iMatch <> 1 Then
For i = 0 to uBound(arrRouter)
If arrrouter(i) = sline Then
oRouterfile.writeline sLine
iMatch = 1
End If
Next
End If
Loop