Heesob Park
4/27/2006 7:30:00 AM
Hi,
You can modify IP setting using win32ole and WMI.
Following code modify ip setting of all ethernet adapters.
Modify sWQLQuery for your environment.
----
require 'win32ole'
ip = "192.168.0.10"
mask = "255.255.255.0"
gw = "192.168.0.1"
dns = ["1.2.3.4","1.2.3.5"]
sWQLQuery = "SELECT * FROM Win32_NetworkAdapter WHERE AdapterType like
'% 802.3' "
mgmt =
WIN32OLE.connect("winmgmts:{impersonationLevel=impersonate}//./root/CIMV2")
mgmt.ExecQuery(sWQLQuery,"WQL").each do |oInstance|
oInstance.Associators_(nil,"Win32_NetworkAdapterConfiguration").each
do |oAssociator|
oMethod = oAssociator.Methods_("EnableStatic")
oInParam = oMethod.InParameters.SpawnInstance_()
oInParam.IPAddress = [ip]
oInParam.SubnetMask = [mask]
oOutParam = oAssociator.ExecMethod_("EnableStatic", oInParam)
oMethod = oAssociator.Methods_("SetGateways")
oInParam = oMethod.InParameters.SpawnInstance_()
oInParam.DefaultIPGateway = [gw]
oInParam.GatewayCostMetric = [1]
oOutParam = oAssociator.ExecMethod_("SetGateways", oInParam)
oMethod = oAssociator.Methods_("SetDNSServerSearchOrder")
oInParam = oMethod.InParameters.SpawnInstance_()
oInParam.DNSServerSearchOrder = dns
oOutParam = oAssociator.ExecMethod_("SetDNSServerSearchOrder",
oInParam)
end
end
Regards,
Park Heesob