$MyIP = Join(Split(@IPADDRESS0, ' '), '') ; "normalize" the IP address
If InSubnet($MyIP, '192.168.2.0/24')
'is in the subnet!' ?
; time to do stuff?
$LastDate = ReadValue('HKLM\Software\MyCompany', 'LastInstallCheckDate')
If TimeDiff($LastDate, 'today', 'D') > 6
; it's been 7 days - run the install!
; update the registry
$LastDate = WriteValue('HKLM\Software\MyCompany', 'LastInstallCheckDate', @DATE, 'REG_SZ')
EndIf
EndIf
; InSubnet function follows - do not modify!
;;
;;======================================================================
;;
;;FUNCTION InSubnet()
;;
;;ACTION Determines if a specific IP address is in a subnet
;;
;;AUTHOR Glenn Barnas
;;
;;VERSION 1.0 / 2008/01/20
;;
;;SYNTAX InSubnet(Address, Network)
;;
;;PARAMETERS Address - REQUIRED, IP address in dotted-decimal (w.x.y.z)
;;
;; Network - REQUIRED, Network in CIDR format (w.x.y.z/mask)
;;
;;REMARKS
;;
;;RETURNS 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