Jump to content
  • 0

IP Check Loop


belphegor

Question


  • Group:  Members
  • Topic Count:  2
  • Topics Per Day:  0.00
  • Content Count:  23
  • Reputation:   0
  • Joined:  08/12/13
  • Last Seen:  

Man, this loop thing is creeping me out. :3

Btw, is this right?

 

EDIT: Oops. Sorry, post's not in the right place :)

for(.@i = 0; .@i < getarraysize(.@names$); .@i + 1) {
    .@checkcount = .@checkcount + 1;
        .@currentcheck$ = getcharip(.@names$[.@i]);
            if(.@currentcheck$ == getcharip(.@names$[.@checkcount]))
                .@dual = .@dual + 1
}
Edited by belphegor
Link to comment
Share on other sites

2 answers to this question

Recommended Posts


  • Group:  Developer
  • Topic Count:  10
  • Topics Per Day:  0.00
  • Content Count:  2407
  • Reputation:   613
  • Joined:  07/05/12
  • Last Seen:  

if(.@currentcheck$]==getcharip($@names$[.@checkcount]))

  • delete the ] in red
  • replace the $ in blue by .

.@dual = .@dual + 1

You forgot ; at the end of this line.

for(.@i = 0; .@i < getarraysize(.@names$); .@i + 1) {

.@i + 1 doesn't increment .@i variable. It must be .@i += 1 or .@i++

 

This script check if the ip in array i is the same in array i+1. But it won't check if the ip in array i is the same in array i+2 etc

 

With 2 loops

.@size = getarraysize(.@names$);
for(.@i = 0; .@i < .@size -1; .@i++ ) {
	.@ip_in_loop1$ = getcharip(.@names$[.@i]);
	for( .@j = .@i +1; .@j < .@size; .@j++ )
		if( .@ip_in_loop1$ == getcharip(.@names$[.@j]) )
            .@dual = .@dual + 1;
}

 

With setd/getd + 1 loop

.@size = getarraysize(.@names$);
for( .@i = 0; .@i < .@size; .@i++ ) {
	if ( getd( ".@ip_"+ getcharip( .@names$[.@i] ) ) )
		.@dual = .@dual + 1;
	setd ".@ip_"+ getcharip(.@names$[.@i]), 1;
}

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  2
  • Topics Per Day:  0.00
  • Content Count:  23
  • Reputation:   0
  • Joined:  08/12/13
  • Last Seen:  

Sorry 'bout those errors. I'm kinda new to this whole loop thing and i've been awake for almost two days now. Btw, i never even thought of using 2 loops. Thanks mate. :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...