[转载]使用脚本自动修改ip设置
<P>信息来源:Wayne_Deng的专栏</P><P>vbs脚本的功能非常强大, 管理系统简单方便!下面的脚本win2000和winxp都可以使用,win2003没有测试过,<BR>应该也没有问题。如果需要经常切换网关,或是ip,这个脚本是最方便的了。稍微修改一下甚至可以做到1分钟变一次ip。<BR><BR></P><PRE class=HTML_file><STRONG>changeip.vbs</STRONG><BR><BR><BR><BR><BR><BR>strComputer = <FONT color=#ff00bf>"."</FONT>
<FONT color=#0000ff><B>Set</B></FONT> objWMIService = GetObject(<FONT color=#ff00bf>"winmgmts:\\"</FONT> <FONT color=#333399>&</FONT> strComputer <FONT color=#333399>&</FONT> <FONT color=#ff00bf>"\root\cimv2"</FONT>)
<FONT color=#0000ff><B>Set</B></FONT> colNetAdapters = objWMIService.ExecQuery _
(<FONT color=#ff00bf>"Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE"</FONT>)
<FONT color=#0000ff><B>For</B></FONT> <FONT color=#0000ff><B>Each</B></FONT> objNetAdapter <FONT color=#0000ff><B>in</B></FONT> colNetAdapters
sip=objNetAdapter.IPAddress
strIPAddress = sip <FONT color=#008000>'保持原来的ip,如果需要修改ip为192.168.0.200:strIPAddress = Array("192.168.0.200")</FONT>
strSubnetMask = Array(<FONT color=#ff00bf>"255.255.255.0"</FONT>)
strGateway = Array(<FONT color=#ff00bf>"192.168.0.254"</FONT>) <FONT color=#008000>'修改网关为192.168.0.254</FONT>
strGatewayMetric = Array(<FONT color=#6e00aa>1</FONT>)
errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
<FONT color=#0000ff><B>If</B></FONT> errEnable = <FONT color=#6e00aa>0</FONT> <FONT color=#0000ff><B>Then</B></FONT>
WScript.Echo <FONT color=#ff00bf>"The IP address has been changed."</FONT>
<FONT color=#0000ff><B>Else</B></FONT>
WScript.Echo <FONT color=#ff00bf>"The IP address could not be changed."</FONT>
<FONT color=#0000ff><B>End</B></FONT> <FONT color=#0000ff><B>If</B></FONT>
<FONT color=#0000ff><B>exit</B></FONT> <FONT color=#0000ff><B>for</B></FONT> <FONT color=#008000>'只修改第一个网卡的设置</FONT>
<FONT color=#0000ff><B>Next</B></FONT>
</PRE>
<P><BR></P>
页:
[1]