Jump to content

IP Checking against an array


Recommended Posts

These 2 functions are a part of my script that log the IP and then save it to an array, if the IP is already in the array it is supposed to run ReIP() again and set the VPN to get a new IP, but it seems that _ArraySearch is always returning an @error and never triggers the 2nd part of the If statement.

I know I must be missing something and a few different pairs of eyes would be a great help!

Func ReIP();This function is clicking VPN buttons to refresh the IP
        MouseClick("right", $ReCordIP1, $ReCordIP2) 
        MouseClick("left", $ReCordIP3, $ReCordIP4)
        Sleep(35000)
        CheckIP()
EndFunc

Func CheckIP();This is my function for getting the ip, checking if its in the array, and then adding if its not / redoing ReIP() if its already in the array
    $PublicIP = _GetIP() ;Gets the WAN IP
        If $PublicIp = -1 Then
            $PublicIP = _GetIP()
        Else
            GUICtrlSetData($IPList, $PublicIP) ;Updates the list to add the current IP
            $Location = _ArraySearch($IP_list, $PublicIP) ;Searching the array
                If @error Then ;This should be if the IP is NOT in the array
                    NextAccount()
                    ;MsgBox(0, "IPConfi", "Ip good to go", 3)
                    _ArrayAdd($IP_list, $PublicIP)
                Else ;If the IP is in the array it executes the function again.
                    ;MsgBox(0, "IPConfi", "Ip already used. Getting new one, message will time out in 3 sec", 3)
                    ReIP()
                EndIf
        EndIf
EndFunc

I tried to add comments to everything to give you a better idea. Tell me if there's anything else in the script you need.

Edited by Tomoya
Link to comment
Share on other sites

You have this line "If @error Then ;This should be if the IP is NOT in the array"

But @Error can have many values and for different reasons, which are explained in the helpfile.

eg:

If @error = 1 Then ;

;1 - $avArray is not an array

EndIf

There are other values. You cannot even begin to debug your problem until you first know what it is.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

.. debugging, debugging, debugging ...

When something does not work - use MsgBox and ConsoleWrite every step.

JohnOne already gave you the first idea and it's the very best one to start. Use a msgBox to display the value for @error and see the explanation. That will tell you what to check next.

Check also your array content, IP value.

Learn to debug or you will be a permanent presence in this forum.

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

.. debugging, debugging, debugging ...

When something does not work - use MsgBox and ConsoleWrite every step.

JohnOne already gave you the first idea and it's the very best one to start. Use a msgBox to display the value for @error and see the explanation. That will tell you what to check next.

Check also your array content, IP value.

Learn to debug or you will be a permanent presence in this forum.

Its something I have put off but I guess nows as good time to learn the next step in my autoit programming :)

I will post back a solution if I find one. Thanks everyone for your help.

Solution:

I guess I need to be alittle more specific with the @error command because technically @error is any possible value and 0 is a value thus @error was always happening.

So @error = 1 fixed the problem. Now have learned how to diagnose my own problems with @error though ;)

Hopefully one day I will be able to come here and help people.

Edited by Tomoya
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...