8 thg 3, 2008

Tự động set IP bằng script

Nếu bạn là quản trị mạng và nhàm chán trong công việc cứ phải set IP thủ công thì bạn có thể set IP bằng đoạn script dưới đây :

strComputer = “.”
Set objWMIService = GetObject(”winmgmts:” _
& “{impersonationLevel=impersonate}!\\” & strComputer & “\root\cimv2″)
Set colNetAdapters = objWMIService.ExecQuery _
(”Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE”)
strIPAddress = Array(”10.4.2.246″)
strSubnetMask = Array(”255.255.255.0″)
strGateway = Array(”10.4.2.1″)
strGatewayMetric = Array(1)

For Each objNetAdapter in colNetAdapters
errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
If errEnable = 0 Then
WScript.Echo “CHANGE IP OK.”
Else
WScript.Echo “CHANGE IP ERROR.”
End If
Next

http://www.how.vn/home/?p=73

Không có nhận xét nào: