thepip3r
(Hey THIS is FUN)
2006-04-22 08:31 PM
Help with Ascan please...

My code is supposed to examine a proxy log line by line and is supposed to pull an element out of that line if it has the first two octets of a certain network in it and then write that IP to a temp array. It's only supposed to add the IP address if the IP has NOT already been previously added. The logic expressed in the last line was attempted below:

Code:
        If AScan($ipAddresses,$arrLine[2]) = -1
ReDim preserve $ipAddresses[Ubound($ipAddresses)+1]
$ipAddresses[ubound($ipAddresses)] = $arrLine[2]
Endif



...for some reason, the array is keeping all entries of all of the IP addresses and I'm only trying to keep one, unique entry. Is there anything obvious that I'm doing wrong?

Sample Output:

192.168.161.125
192.168.161.92
192.168.163.74
192.168.161.125
192.168.161.92
192.168.163.74
192.168.161.125
192.168.161.92
192.168.163.74
192.168.161.125
192.168.161.92
192.168.163.74
192.168.161.125
192.168.161.92
192.168.183.24


Les
(KiX Master)
2006-04-22 09:46 PM
Re: Help with Ascan please...

AScan() by default only does an exact match, not a partial. If you want a partial match on just the first two octets, you need the latest version of KiX and more parms.


From the 4.52b beta liner notes:
Quote:


4) Added an option to AScan to return all matching elements.

The 'Mode' parameter of AScan now takes a bitpattern as input with the
following possible values:

bit 0 0 = search for exact match (default) 1 - do an instr() scan
bit 1 0 = return first matching element 1 - return all elements

Examples:

AScan( $Array, $String,,, 0) ; scan for exact match and return 1st hit
AScan( $Array, $String,,, 1) ; use InStr() and return 1st hit
AScan( $Array, $String,,, 2) ; scan for exact match and return all hits
AScan( $Array, $String,,, 3) ; use InStr() and return all hits






thepip3r
(Hey THIS is FUN)
2006-04-22 10:33 PM
Re: Help with Ascan please...

bah crap... thanx Les. I can use SubStr though with the current stable release to get what I'm looking for right?

well it's going to have to cuz that's what i'm going to try. =P


thepip3r
(Hey THIS is FUN)
2006-04-22 10:37 PM
Re: Help with Ascan please...

bah... nm Les. I confused myself thinking I was doing a partial match but I'm not. Here's more of the code so you can see actually waht's going on:

Code:
If $OpenRawFile = 0 AND $OpenReorgFile = 0
$line = ReadLine(1)
Do
If (instr($line,'192.168'))
$arrLine = Split($line,' ')
If AScan($ipAddresses,$arrLine[2]) = -1
ReDim preserve $ipAddresses[Ubound($ipAddresses)+1]
$ipAddresses[ubound($ipAddresses)] = $arrLine[2]
Endif

If Ubound($ipAddresses) <> -1
for each $x in $ipAddresses
$ = WriteLine(2,$x + @CRLF)
next
Endif
Endif
$line = ReadLine(1)
Until @ERROR <> 0

? 'Success!' + @CRLF
Else
? 'Opening Files Failed!' + @CRLF
Endif



...see, i'm trying to just make sure that the array element follows my ip address scheme and if it does, then i check to see if the WHOLE IP address already exists in the array. It always add the duplicated IPs into my temp array though.. =/


thepip3r
(Hey THIS is FUN)
2006-04-23 12:05 AM
Re: Help with Ascan please...

Hmm... found something even more weird now, when I print out @ERROR and my array element, they show up correct in the conditional but seem to still be writing bad information to the document... i don't get it...

Code:

If $OpenRawFile = 0 AND $OpenReorgFile = 0
$line = ReadLine(1)
Do
If (instr($line,'153.29'))
$arrLine = Split($line,' ')
If AScan($ipAddresses,$arrLine[2]) = -1
? 'AScan ERROR Status: '+@ERROR+@CRLF
? $arrLine[2] + @CRLF
sleep 1
ReDim preserve $ipAddresses[Ubound($ipAddresses)+1]
$ipAddresses[ubound($ipAddresses)] = $arrLine[2]
Endif

If Ubound($ipAddresses) <> -1
for each $x in $ipAddresses
$ = WriteLine(2,$x + @CRLF)
next
Endif
Endif
$line = ReadLine(1)
Until @ERROR <> 0

? 'Success!' + @CRLF
Else
? 'Opening Files Failed!' + @CRLF
Endif

$ = Close(2)
$ = Close(1)



Les
(KiX Master)
2006-04-23 12:26 AM
Re: Help with Ascan please...

I don't think your problem is with AScan(). You keep iterating through a Do While loop and on every iteration of the loop, you also loop through your $ipaddresses array and write out the ENTIRE array.

thepip3r
(Hey THIS is FUN)
2006-04-23 12:48 AM
Re: Help with Ascan please...

right and that's what i'm trying to do... ok here's my logic Les and tell me if i'm totally jacked up or not:

as I scan each line of the proxy file, if the line has '192.168' in it, it allows further processing. That line is then split into elements of an array seperated by a space character. For every third element, it's supposed to scan my temp array ($ipAddresses) and if that value DOESN'T already exist in the array, it adds that new element to the array. (So at this point, I should have a temp of array of only the unique ip addresses, right?) Then I just write out all elements of that array into my text file...

Is that not how you see the logic of my script?


Les
(KiX Master)
2006-04-23 01:04 AM
Re: Help with Ascan please...

Quote:

Then I just write out all elements of that array into my text file...



Wrong!
You write out the array on EVERY iteration of your Do While loop. Move your For Each loop out of the Do While loop.


thepip3r
(Hey THIS is FUN)
2006-04-23 01:18 AM
Re: Help with Ascan please...

First off, I'd like to thank you because that fixed my problem; it's always the freakin simplest logic problems i miss... =/ Thanx again for showing me the error of my ways Les. =D