Jump to content

Compare Ip To Mask


bcording
 Share

Recommended Posts

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
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...