Sign in to follow this  
Followers 0
bcording

Compare Ip To Mask

1 post in this topic

This function accepts an IP address and a mask to compare it to and returns either a o if false or a 1 if true. For the mask you can replace octets with an asterisk as a wild card. The function accepts mutltiple wildcards.

Examples:

CompareIP("10.0.0.1","10.0.0.*") = True

CompareIP("10.000.000.001","10.0.0.*") = True

CompareIP("10.0.0.1","10.*") = True

CompareIP("10.0.0.1","*.*.*.2") = False

Func CompareIP($IP, $Mask)
    Local $i

    $IP = StringSplit($IP, ".")
    $Mask = StringSplit($Mask, ".")

    For $i = 1 To ubound($mask) -1
        If $Mask[$i] <> "*" Then
            If int($IP[$i]) <> int($Mask[$i]) Then Return 0
        EndIf
    Next
    Return 1
EndFunc

Share this post


Link to post
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
Sign in to follow this  
Followers 0