#161048 - 2006-04-22 08:31 PM
Help with Ascan please...
|
thepip3r
Hey THIS is FUN
Registered: 2005-03-02
Posts: 350
|
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
Edited by thepip3r (2006-04-22 08:38 PM)
|
Top
|
|
|
|
#161049 - 2006-04-22 09:46 PM
Re: Help with Ascan please...
|
Les
KiX Master
Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
|
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
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.
|
Top
|
|
|
|
#161051 - 2006-04-22 10:37 PM
Re: Help with Ascan please...
|
thepip3r
Hey THIS is FUN
Registered: 2005-03-02
Posts: 350
|
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.. =/
Edited by thepip3r (2006-04-22 11:38 PM)
|
Top
|
|
|
|
#161052 - 2006-04-23 12:05 AM
Re: Help with Ascan please...
|
thepip3r
Hey THIS is FUN
Registered: 2005-03-02
Posts: 350
|
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)
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 507 anonymous users online.
|
|
|