建议增加查询条件,更准确地修改指定网卡。 本人是铁通的线路,这样看比较不错的wsh功能呢,喜欢vbs的朋友,可以用vbs实现,功能更强
复制代码 代码如下:
var WMI = GetObject("winmgmts://127.0.0.1");
var sql = "select * from Win32_NetworkAdapterConfiguration where IPEnabled=true";
var enmPing = new Enumerator(WMI.ExecQuery(sql));
var arrAdp = new Array;
while(!enmPing.atEnd())
{
var arrIP = new Array;
var objIP = enmPing.item();
arrIP.push("网卡说明:" + objIP.Description);
arrIP.push("硬件地址:" + objIP.MACAddress);
arrIP.push("动态地址:" + (objIP.DHCPEnabled ? "是" : "否"));
arrIP.push("网络地址:" + GetVBArray(objIP.IPAddress));
arrIP.push("域名解析:" + GetVBArray(objIP.DNSServerSearchOrder));
arrIP.push("子网掩码:" + GetVBArray(objIP.IPSubnet));
arrIP.push("默认网关:" + GetVBArray(objIP.DefaultIPGateway));
/* 将首选DNS设置为220.192.0.130,第二DNS设置为220.192.32.103 */
//objIP.SetDNSServerSearchOrder(["220.192.0.130", "220.192.32.103"]);
arrAdp.push(arrIP.join("\r\n"));
enmPing.moveNext();
}
WSH.Echo(arrAdp.join("\r\n\r\n"));
function GetVBArray(arr)
{
return arr !== null ? new VBArray(arr).toArray() : [];
}
执行结果:
复制代码 代码如下:
---------------------------
Windows 脚本宿主
---------------------------
网卡说明:Realtek RTL8139 Family PCI Fast Ethernet NIC
硬件地址:00:E0:4C:E7:15:A2
动态地址:是
网络地址:169.254.44.245
域名解析:
子网掩码:255.255.0.0
默认网关:
网卡说明:WAN (PPP/SLIP) Interface
硬件地址:00:53:45:00:00:00
动态地址:否
网络地址:122.89.157.174
域名解析:222.45.1.122,222.45.1.40
子网掩码:255.255.255.255
默认网关:122.89.157.174
---------------------------
确定
---------------------------