Break On
$Networks = '10.1.0.0/24','10.18.22.0/24','10.64.61.0/24'
$Printers = '\\server\printer1','\\server\printer2','\\server\printer3'
$Mapped = 0
$MyIP = Join(Split(@IPADDRESS0, ' '), '')
For $I = 0 to UBound($Networks)
If InSubnet($MyIP, $Networks[$I])
'My ip address (' $MyIP ') exists in network $I (' $Networks[$I] ')' ?
'Mapping printer ' $Printers[$I] ?
$Mapped = 1
EndIf
Next
If Not $Mapped
'No printers were mapped!' ?
EndIf
; InSubnet UDF available from http://wws.innotechcg.com w/ full header info
Function InSubnet($_IPAddr, $_Network)
Dim $_aAdd ; array of address values
Dim $_Mask ; Mask value
Dim $_Hosts ; hosts in subnet
; 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