have a look at some functions i recently wrote for the same reason :
 Code:
function ConvertIpAddrToArray( $ipstr )
    dim $i, $num

    select
        case vartype($ipstr)=8      ;-- chaine de caractères --
            dim $i

            $ipstr = replace( $ipstr, " ", "" )
            $ipstr = split( $ipstr, "." )
            if ubound($ipstr)<>3        exit 1      endif

        case UBound($ipstr)=3       ;-- tableau de 4 éléments --

            ;-- le controle sera fait dans le bloc commun --
        case 1
            exit 1
    endselect

    ;-- controle des 4 entrées du tableau --
    for $i = 0 to UBound($ipstr)
        $num = val($ipstr[$i])
        if val($num) <> $ipstr[$i]        exit 1        endif
        if ($num<0) or ($num>255)        exit 1        endif

        $ipstr[$i] = $num
    next

    $ConvertIpAddrToArray = $ipstr
    exit 0
endfunction


function ConvertIPMaskToArray( $mask )
    $ConvertIPMaskToArray = ConvertIpAddrToArray($mask)
    if @error
        ;-- controleur : valeur doit être entre 1 et 32 (inclus) --
        $mask = val($mask)
        if ($mask<=0) or ($mask>32)     exit 1      endif

        redim $ConvertIPMaskToArray[3]

        dim $s, $i, $j

        $s = ""
        for $i = 1 to $mask
            $s = $s + "1"
        next

        while len($s)<32
            $s = $s + "0"
        loop

        $j = 1
        for $i = 0 to 3
            $ConvertIPMaskToArray[$i] = BinToDec( substr($s,$j,8) )
            $j = $j + 8
        next
    endif

    exit 0
endfunction

function CompareIPAddr( $ip1, $ip2 )
    $CompareIPAddr = (0=1)

    $ip1 = ConvertIpAddrToArray( $ip1 )
    if @error   exit 1  endif

    $ip2 = ConvertIpAddrToArray( $ip2 )
    if @error   exit 1  endif

    dim $i

    for $i = 0 to 3
        if $ip1[$i]<>$ip2[$i]   exit    endif
    next

    $CompareIPAddr = (1=1)
endfunction


function IsIPAddrInSubnet( $ip, $subnet, $subnetmask )
    $IsIPAddrInSubnet = (0=1)

    $ip = ConvertIpAddrToArray( $ip )
    if @error   exit 1  endif

    $subnet = ConvertIpAddrToArray( $subnet )
    if @error   exit 2  endif

    $subnetmask = ConvertIpMaskToArray( $subnetmask )
    if @error   exit 3  endif

    dim $i

    $IsIPAddrInSubnet = (1=1)
    for $i = 0 to 3
        if ($ip[$i] & $subnetmask[$i]) <> $subnet[$i]
            $IsIPAddrInSubnet = (0=1)
            exit 4
        endif
    next
endfunction


function ApplyIPMaskToIPAddr( $IPMask, $IPAddr )

    $ipaddr = ConvertIpAddrToArray( $ipaddr )
    if @error   exit 1  endif

    $ipmask = ConvertIpMaskToArray( $ipmask )
    if @error   exit 2  endif

    redim $ApplyIPMaskToIPAddr[3]
    dim $i

    for $i = 0 to 3
        $ApplyIPMaskToIPAddr[$i] = $IPAddr[$i] & $IPMask[$i]
    next
endfunction


function ConvertIPArrayToString( $ip )
    $ConvertIPArrayToString = ""
    $ip = ConvertIpAddrToArray( $ip )
    if @error   exit @error  endif

    $ConvertIPArrayToString = join( $ip, "." )
endfunction


function BinToDec( $str )
    dim $num, $i, $j
    $num = 0
    $j = 1
    for $i = len($str) to 1 step -1
        $num = $num + $j*val(substr($str,$i,1))
        $j = $j * 2
    next
    $BinToDec = $num
endfunction


- function ConvertIpAddrToArray( $ipstr )
- function ConvertIPMaskToArray( $mask )
- function CompareIPAddr( $ip1, $ip2 )
- function IsIPAddrInSubnet( $ip, $subnet, $subnetmask )
- function ApplyIPMaskToIPAddr( $IPMask, $IPAddr )

the most interesting for you is IsIPAddrInSubnet.
You give the IP to test, the IP of the subnet and the mask of the subnet (in IP format or in number of bits) and the function returns a boolean.

example :
- IsIPAddrInSubnet( "192.168.1.127", "192.168.1.0", "24" ) returns 1
- IsIPAddrInSubnet( "192.168.1.127", "192.168.1.0", "25" ) returns 1
- IsIPAddrInSubnet( "192.168.1.127", "192.168.1.0", "26" ) returns 0

My library is not complete because i could calculate some other informations :
- first ip addr of a subnet
- last ip addr of the subnet
- broadcast IP address
- binary mask,
- reverse mask for switch
but today i have no need of theses.

i should document the header of functions and translate "french" comments in the code. Now, i have not enough time !!!
_________________________
Christophe