MasterRacker
New member
I'm using the script below on a utility notebook that I need to change address on regularly. It works fine except that it not only canges address on the physical NIC but it also tries to set the virtual NIC installed by Sun VirtualBox.
What's a good way to filter the collection of NICS to only work with physical NICS?
Jeff
[small][purple]It's never too early to begin preparing for [/purple]International Talk Like a Pirate Day
"The software I buy sucks, The software I write sucks. It's time to give up and have a beer..." - Me[/small]
What's a good way to filter the collection of NICS to only work with physical NICS?
Code:
'===============================================================================
' NAME: MultiSetIP.vbs
' AUTHOR: Jeff Xxxxxxx
' DATE: 02/01/2010
' DESCRIPTION:
' Set IP address for Panasonic DVR or Bbb VLAN access.
' Command line argument 'D' resets to DHCP.
' Compiled from various sources
'===============================================================================
strComputer = "."
set objWMIService = GetObject ("winmgmts:" & "{impersonationLevel = impersonate}!\\" & strComputer & "\root\cimv2")
set colAdapters = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
arg = UCase(InputBox("Enter network. (D=DHCP, B=Bbb VLAN, P=Panasonic DVR):")
if arg = "D" then
SetDHCP
else
SetStatic(arg)
end if
sub SetStatic(net)
useDNS = FALSE
strGatewayMetric = Array(1)
arrDNSServers = Array("10.10.1.1", "10.10.1.2")
select case net
case "P"
strIPAddress = Array("192.168.0.11")
strSubnetMask= Array("255.255.255.0")
strGateway = Array("192.168.0.1")
case "B"
strIPAddress = Array("10.20.10.175")
strSubnetMask= Array("255.255.0.0")
strGateway = Array("10.20.10.254")
useDNS = TRUE
case else
Wscript.Echo "Invalid network. USAGE: MultiSetIP <D|B|P> (D=DHCP, B=Bbb VLAN, P=Panasonic DVR)"
Wscript.Quit
end select
for each objAdapter in colAdapters
errIP = objAdapter.EnableStatic(strIPAddress,strSubnetMask)
errGateway= objAdapter.SetGateways(strGateway, strGatewayMetric)
if errIP = 0 and errGateway = 0 then
WScript.Echo "IP address configured."
elseif errIP = 1 or errGateway = 1 then
WScript.Echo "You must reboot for the changes to take effect."
else
WScript.Echo "Unable to configure IP address. IP: " & errIP & " and Gateway:" & errGateway
end if
if useDNS then
errDNS = objAdapter.SetDNSServerSearchOrder(arrDNSServers)
If errDNS = 0 Then
WScript.Echo " DNS Servers set."
Else
WScript.Echo " Error setting DNS server info."
End If
end if
next
end sub
sub SetDHCP()
for each objAdapter in colAdapters
errDHCP = objAdapter.EnableDHCP()
if errDHCP = 0 then
Wscript.Echo "DHCP has been enabled."
else
Wscript.Echo "DHCP could not be enabled."
end if
errDNS = objAdapter.SetDNSServerSearchOrder()
errDDNS = objAdapter.SetDynamicDNSRegistration
errRenew = objAdapter.RenewDHCPLease
if errRenew <> 0 then
Wscript.Echo "DHCP lease could not be renewed." & err.number & err.description
end if
next
end sub
Jeff
[small][purple]It's never too early to begin preparing for [/purple]International Talk Like a Pirate Day
"The software I buy sucks, The software I write sucks. It's time to give up and have a beer..." - Me[/small]