Page 1 of 1 1
Topic Options
#161048 - 2006-04-22 08:31 PM Help with Ascan please...
thepip3r Offline
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 Offline
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
#161050 - 2006-04-22 10:33 PM Re: Help with Ascan please...
thepip3r Offline
Hey THIS is FUN
*****

Registered: 2005-03-02
Posts: 350
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


Edited by thepip3r (2006-04-22 10:34 PM)

Top
#161051 - 2006-04-22 10:37 PM Re: Help with Ascan please...
thepip3r Offline
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 Offline
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
#161053 - 2006-04-23 12:26 AM Re: Help with Ascan please...
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
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.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#161054 - 2006-04-23 12:48 AM Re: Help with Ascan please...
thepip3r Offline
Hey THIS is FUN
*****

Registered: 2005-03-02
Posts: 350
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?


Edited by thepip3r (2006-04-23 12:49 AM)

Top
#161055 - 2006-04-23 01:04 AM Re: Help with Ascan please...
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
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.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#161056 - 2006-04-23 01:18 AM Re: Help with Ascan please...
thepip3r Offline
Hey THIS is FUN
*****

Registered: 2005-03-02
Posts: 350
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
Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 507 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.059 seconds in which 0.026 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org