在Unix下有shell,在Windows下有Javascript。
玩得好,Javascript也能完成Shell的所有功能,甚至更出色。
为了证明这一点,我准备努力研究这个专题。
今天先奉上一段修改IP地址的Javascript 脚本。
--------------------------------------------------------------
function setIP(objNetAdapter)
{
var strIPAddress = new Array("192.168.0.1");
var strSubnetMask = new Array("255.255.255.0");
var strGateway = new Array("192.168.1.100");
var strGatewayMetric = new Array("1");
var errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask);
var errGateways = objNetAdapter.SetGateways(strGateway, strGatewayMetric);
if(errEnable == 0)
{
WScript.Echo("The IP address has been changed.");
}
else
{
WScript.Echo("The IP address could not be changed.");
}
}
function setupIP()
{
var objWMIService = GetObject("winmgmts:\\\\.\\root\\CIMV2");
var colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration where IPEnabled=TRUE and Index=14", "WQL",wbemFlagReturnImmediately | wbemFlagForwardOnly);
var enumItems = new Enumerator(colItems);
if(!enumItems.atEnd())
{
setIP(enumItems.item());
}
else
{
WScript.Echo("no network adapter found!");
}
}
----------------------------------------------------------------
就这么几行,就可以指定IP了,如果有心细化,还能做得更好。
接下来的目标是修改无线网卡的参数。
阅读(1023) | 评论(0) | 转发(0) |