Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
Keywords: ip address subnet local valid range scope
However, that site may have many local subnets (10.10.0.0/24, 10.10.1.0/28, 10.10.2.0/23, etc).
This local subnets won't match up exactly with a AD Site subnet. I need to somehow determine if a given IP is valid within the larger scope.
10.10.3.1 is valid within 10.10.0.0/21.Does anyone know of any code robust enough to tell me if a given IP is valid within a given scope?
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; UDF_GetIPNetwork ; Version 1.0 ; ; Decription: Uses binary and to compare the IP address and its subnet mask to determine the IP network. ; ; Dependencies: ; ; Global Variables: ; ; Inputs: vstrIPAddress ; versSubnet ; ; Outputs: IP Network ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; #DefineFunction UDF_GetIPNetwork(vstrIPAddress,vstrSubnet) ; Turn the IP address and subnet mask into arrays varrIP = Arrayize(vstrIPAddress,".") varrSubnet = Arrayize(vstrSubnet,".") vstrNetwork = "" ; use binary anding to determine the network For vintCounter = 0 To 3 vstrNetwork = ItemInsert((varrIP[vintCounter] & varrSubnet[vintCounter]), -1,vstrNetwork,".") Next Return(vstrNetwork) #EndFunction
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Convert dotted IP to integer ;; ;; Parameter: strIP - dot delimited IP Address ;; ;; Notes: Needs additional IP address validation ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; #DefineFunction MakeIntIp(strIp) If ItemCount(strIp, '.') != 4 Then Return 0 nIp = 0 For i = 1 To 4 nIp = nIp << 8 nIp = nIp + ItemExtract(i,strIp,'.') Next Return nIp #EndFunction ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Create a net mask by brute force. ;; ;; Parameter: nSigBits - number of most ;; significant bits in network part ;; of IP addresses. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; #DefineFunction MakeNetMask(nSigBits) If nSigBits >= 32 Then Return -1 If nSigBits <= 0 Then Return 0 nMask = 0 For i = 1 To nSigBits nMask = nMask<<1 nMask = nMask + 1 Next nMask = nMask<<(32-nSigBits) Return nMask #EndFunction AD_SubnetLength = 27 nMask = MakeNetMask(AD_SubnetLength) AD_Decimal = "10.10.8.0" AD_Binary = MakeIntIp(AD_Decimal) AD_Network = AD_Binary & nMask Office_Decimal = "10.10.10.254" Office_Binary = MakeIntIp(Office_Decimal) Office_Network = Office_Binary & nMask If AD_Network == Office_Network Message("Success", "They Match") Else Message("Failure", "They Do NOT Match") EndIf
Article ID: W18375
Filename: Check If IP Address Is in Subnet.txt
File Created: 2011:03:28:08:06:58
Last Updated: 2011:03:28:08:06:58