; Subnet ; will Identify if a given IP address is in a specified subnet ; ; Requirements: BInaryIP() ; ; SYNTAX: SUBNET([ipaddress], [ipmask], [subnetmask]) ; [ipaddress] is the Ip Address that you wnat to check against. ; [IPmask] Is the ip mask of the subnet you are compairing [ipaddress] to ; [subnet] is the subnet range of the [ipmask] ; ; Return Codes ; 1 = [ipaddress] is in the subnet specified ; 0 = [ipaddress] is NOT in the subnet specified ; ; Example: ; if subnet("10.0.0.1", "10.0.0.0", "255.0.0.0") = 1 ; ? "this ipaddress is in the specified subnet." ; else ; ? "this ipaddress is not in the specified subnet." ; endif Function Subnet($ipaddress, $ipmask, $subnetmask) if instr(binaryip($subnetmask),"0") <> 0 $subnetmask = substr(binaryip($subnetmask),1,instr(binaryip($subnetmask),0)-1) else $subnetmask = binaryip($subnetmask) endif if substr(binaryip($ipaddress),1,len("$subnetmask")) = substr(binaryip($ipmask),1,len("$subnetmask")) $subnet = 1 else $subnet = 0 endif endfunction ; Binary IP ; Returns a binary string repesenting an ip address. ; ; Requirements: NONE ; ; SYNTAX: BinaryIP("IPNUMBER") ; IPNUMBER can be any ip address ; function BinaryIP($IP) DIM $item, $bitsize, $octet $bitsize = 128 $ip = split($IP,".") select case UBOUND($ip) <> 3 $BinaryIP = 0 exit(87) case 1 for each $octet in $ip if VAL($octet) <0 OR VAL($octet) > 255 $BinaryIP = 0 exit(87) endif while $bitsize > 0 if val($octet) & $bitsize $Binary = $Binary + "1" else $Binary = $Binary + "0" endif $bitsize = $bitsize / 2 loop $binaryIP = $binaryIP + "$binary" $bitsize = 128 $binary = "" next endselect exit(0) endfunction