Eg logic of how I think the script should work
Return workstations IP address (172.16.3.20 with subnet 255.255.255.0)
Compare workstation address to list of addresses 172.16.2.#, 172.16.3.#,
172.16.4.# all with the same subnet of 255.255.255.0
depending on the IP address match, map drives J: etc to closest server.
Any pointers and or web sites that might have example code would be great.
Thanks
Jonesy
Hi
Here is a previous script I've made that might help get you started:
bInsideIpRange = False ' init value
aNICstatus = GetIPAddresses()
For i = 0 To Ubound(aNICstatus)
sIP = aNICstatus(i)
aOctet = Split(sIP, ".")
sOctet1 = aOctet(0)
sOctet2 = aOctet(1)
sOctet3 = aOctet(2)
sOctet4 = aOctet(3)
If sOctet1 = 192 And sOctet2 = 168 And sOctet3 = 0 Then
If sOctet4 > 0 And sOctet4 < 31 Then
bInsideIpRange = True
Exit For
End If
End If
Next
If bInsideIpRange Then
WScript.Echo "IP address is inside range 192.168.0.1-192.168.0.30"
End If
Function GetIPAddresses()
'=====
' Based on a Michael Harris script, modified be Torgeir Bakken
'
' Returns array of IP Addresses as output
' by ipconfig or winipcfg...
'
' Win98/WinNT have ipconfig (Win95 doesn't)
' Win98/Win95 have winipcfg (WinNt doesn't)
'
' Note: The PPP Adapter (Dial Up Adapter) is
' excluded if not connected (IP address will be 0.0.0.0)
' and included if it is connected.
'=====
set sh = createobject("wscript.shell")
set fso = createobject("scripting.filesystemobject")
Set Env = sh.Environment("PROCESS")
if Env("OS") = "Windows_NT" then
workfile = Env("TEMP") & "\" & fso.gettempname
sh.run "%comspec% /c ipconfig >" & Chr(34) & workfile & Chr(34),0,true
else
'winipcfg in batch mode sends output to
'filename winipcfg.out
workfile = "winipcfg.out"
sh.run "winipcfg /batch" ,0,true
end if
set sh = nothing
set ts = fso.opentextfile(workfile)
data = split(ts.readall,vbcrlf)
ts.close
set ts = nothing
fso.deletefile workfile
set fso = nothing
arIPAddress = array()
index = -1
for n = 0 to ubound(data)
if instr(data(n),"IP Address") then
parts = split(data(n),":")
'if trim(parts(1)) <> "0.0.0.0" then
if instr(trim(parts(1)), "0.0.0.0") = 0 then
index = index + 1
ReDim Preserve arIPAddress(index)
arIPAddress(index)= trim(cstr(parts(1)))
end if
end if
next
GetIPAddresses = arIPAddress
End Function
--
torgeir
Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of the 1328 page
Scripting Guide: http://www.microsoft.com/technet/scriptcenter