;; 
;;=====================================================================================----- 
;; 
;;FUNCTION       InSubnet() 
;; 
;;ACTION         Determines if a specific IP address is in a given network subnet 
;; 
;;AUTHOR         Glenn Barnas 
;; 
;;VERSION        1.0  - 2008/01/20 
;; 
;;HISTORY        1.0  - 2008/01/20 - Initial Release 
;; 
;;SYNTAX         InSubnet(Address, Network) 
;; 
;;PARAMETERS     Address - REQUIRED - String 
;;               - IP address in dotted-decimal (w.x.y.z) 
;; 
;;		 Network - REQUIRED - String 
;;               - Network to check in CIDR format (w.x.y.z/mask) 
;; 
;;REMARKS        Useful for checking locations by subnet during logon 
;; 
;;RETURNS        Int - 1 if ip address is in the defined subnet, 0 otherwise 
;; 
;;DEPENDENCIES   none 
;; 
;;TESTED WITH    W2K, WXP, W2K3, Vista, X64 
;; 
;;EXAMPLES       If InSubnet('192.168.12.243', '192.168.8.0/21') 
;;		   'Is in subnet!' ? 
;;		 EndIf 
; 
Function InSubnet($_IPAddr, $_Network)
 
  Dim $_aAdd				; array of address values 
  Dim $_Mask				; Mask value 
  Dim $_Hosts				; hosts in subnet 
  Dim $_I				; Index counter 
 
  ; Convert the supplied IP address to a double value representing the decimal address 
  $_aAdd = Split($_IPAddr, '.')
  $_IPAddr = (CDbl($_aAdd[0]) * 16777216.0) + (CDbl($_aAdd[1]) * 65536.0) + (CDbl($_aAdd[2]) * 256.0) + (CDbl($_aAdd[3]) * 1.0)
 
  ; Convert the network from a w.x.y.z/mask format to a decimal value 
  ; this is the starting network address value 
  $_Network = Split($_Network, '/')
  $_Mask = Val($_Network[1])
  $_aAdd = Split($_Network[0], '.')
  $_Network = (CDbl($_aAdd[0]) * 16777216.0) + (CDbl($_aAdd[1]) * 65536.0) + (CDbl($_aAdd[2]) * 256.0) + (CDbl($_aAdd[3]) * 1.0)
 
  ; Set the number of hosts in the defined network 
  $_Hosts = 1.0
  For $_I = 31 to $_Mask Step -1
    $_Hosts = ($_Hosts * 2.0)
  Next
 
  ; return the value  
  $InSubnet = 0
  If $_IPAddr >= $_Network And $_IPAddr < ($_Network + $_Hosts)
    $InSubnet = 1
  EndIf
 
  Exit 0
 
EndFunction