Code _ javascript skills for modifying and viewing IP configurations using WSH

Source: Internet
Author: User
We recommend that you add query conditions to modify the specified Nic more accurately. I am an iron-Tong Line. This looks like a good wsh function. If you like vbs, you can use vbs for better functionality. The Code is as follows:


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 ("Nic Description:" + objIP. Description );
ArrIP. push ("hardware address:" + objIP. MACAddress );
ArrIP. push ("Dynamic Address:" + (objIP. DHCPEnabled? "Yes": "no "));
ArrIP. push ("Network Address:" + GetVBArray (objIP. IPAddress ));
ArrIP. push ("domain name resolution:" + GetVBArray (objIP. DNSServerSearchOrder ));
ArrIP. push ("subnet mask:" + GetVBArray (objIP. IPSubnet ));
ArrIP. push ("Default Gateway:" + GetVBArray (objIP. DefaultIPGateway ));
/* Set the preferred DNS to 220.192.0.130, and the second DNS to 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 "));
Function GetVBArray (arr)
{
Return arr! = Null? New VBArray (arr). toArray (): [];
}

Save it as IpInfo. jse or IpInfo. js and double-click it to run it.
Execution result:

The Code is as follows:


---------------------------
Windows Script Host
---------------------------
NIC Description: Realtek RTL8139 Family PCI Fast Ethernet NIC
Hardware address: 00: E0: 4C: E7: 15: A2
Dynamic Address: Yes
Network Address: 169.254.44.245
Domain name resolution:
Subnet Mask: 255.255.0.0
Default Gateway:

Nic Description: WAN (PPP/SLIP) Interface
Hardware address: 00: 53: 45: 00: 00: 00
Dynamic Address: No
Network Address: 122.89.157.174
Domain name resolution: 222.45.1.122, 222.45.1.40
Subnet Mask: 255.255.255.255
Default Gateway: 122.89.157.174
---------------------------
OK
---------------------------

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.