Recipe 12.1. Viewing the Network Configuration


Problem

You want to view the network configuration of a computer, including a list of all installed network adapters.

Solution

Using a graphical user interface

  1. From the Control Panel, open the Network Connections applet.

  2. Open the network connection for which you want to view the settings.

  3. Click the Properties button.

  4. Click the Configure button to view network adapter properties. Or double-click Internet Protocol (TCP/IP) to view network configuration settings.

Using a command-line interface

To view the list of connections and network configuration on the local system, run the following command:

> ipconfig /all

To view this information on a remote system, use the Sysinternals psexec command:

> psexec \\<ComputerName> -u administrator -p MyPass ipconfig /all

Another command you can use to view network configuration information is netsh, as shown here:

> netsh int ip show config

Using VBScript
' This code displays the network configuration for all connections. ' ------ SCRIPT CONFIGURATION ------ strComputer = "." ' ------ END CONFIGURATION --------- set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") set colNAs = objWMI.InstancesOf("Win32_NetworkAdapter") for each objNA in colNAs     Wscript.Echo objNA.Name     Wscript.Echo "  Description:  " & objNA.Description     Wscript.Echo "  Product Name: " & objNA.ProductName     Wscript.Echo "  Manufacturer: " & objNA.Manufacturer     Wscript.Echo "  Adapter Type: " & objNA.AdapterType     Wscript.Echo "  AutoSense:    " & objNA.AutoSense     Wscript.Echo "  MAC Address:  " & objNA.MACAddress     Wscript.Echo "  Maximum Speed:" & objNA.MaxSpeed     Wscript.Echo "  Conn Status:  " & objNA.NetConnectionStatus     Wscript.Echo "  Service Name: " & objNA.ServiceName     Wscript.Echo "  Speed:        " & objNA.Speed     set colNACs = objWMI.ExecQuery(" select * from " & _                                    " Win32_NetworkAdapterConfiguration " & _                                    "  where Index = " & objNA.Index)     ' There should only be one item in colNACs     for each objNAC in colNACs        if IsArray(objNAC.IPAddress) then           for each strAddress in objNAC.IPAddress              Wscript.Echo "  Network Addr: " & strAddress           next        end if        Wscript.Echo "  IP Metric:    " & objNAC.IPConnectionMetric        Wscript.Echo "  IP Enabled:   " & objNAC.IPEnabled        Wscript.Echo "  Filter:       " & objNAC.IPFilterSecurityEnabled        Wscript.Echo "  Port Security:" & objNAC.IPPortSecurityEnabled        if IsArray(objNAC.IPSubnet) then           for each strAddress in objNAC.IPSubnet              Wscript.Echo "  Subnet Mask:  " & strAddress           next        end if        if IsArray(objNAC.DefaultIPGateway) then           for each strAddress in objNAC.DefaultIPGateway              Wscript.Echo "  Gateway Addr: " & strAddress           next        end if        Wscript.Echo "  Database Path:" & objNAC.DatabasePath        Wscript.Echo "  DHCP Enabled: " & objNAC.DHCPEnabled        Wscript.Echo "  Lease Expires:" & objNAC.DHCPLeaseExpires        Wscript.Echo "  Lease Obtained: " & objNAC.DHCPLeaseObtained        Wscript.Echo "  DHCP Server:  " & objNAC.DHCPServer        Wscript.Echo "  DNS Domain:   " & objNAC.DNSDomain        Wscript.Echo "  DNS For WINS: " & objNAC.DNSEnabledForWINSResolution        Wscript.Echo "  DNS Host Name:" & objNAC.DNSHostName        if IsArray(objNAC.DNSDomainSuffixSearchorder) then           for each strName in objNAC.DNSDomainSuffixSearchOrder              Wscript.Echo "  DNS Suffix Search Order: " & strName           next        end if        if IsArray(objNAC.DNSServerSearchOrder) then           for each strName in objNAC.DNSServerSearchOrder              Wscript.Echo "  DNS Server Search Order: " & strName           next        end if        Wscript.Echo "  Domain DNS Reg Enabled: " & _                        objNAC.DomainDNSRegistrationEnabled        Wscript.Echo "  Full DNS Reg Enabled: " & _                        objNAC.FullDNSRegistrationEnabled        Wscript.Echo "  LMHosts Lookup:      " & objNAC.WINSEnableLMHostsLookup        Wscript.Echo "  WINS Lookup File:    " & objNAC.WINSHostLookupFile        Wscript.Echo "  WINS Scope ID:       " & objNAC.WINSScopeID        Wscript.Echo "  WINS Primary Server: " & objNAC.WINSPrimaryServer        Wscript.Echo "  WINS Secondary:      " & objNAC.WINSSecondaryServer     next     WScript.Echo next

Discussion

There are several different ways to get at the network configuration of a host, as we showed in the Solution section. And since the scripting solution used WMI, there is yet another way using wmic. Here are two commands that display some of the properties of the Win32_NetworkAdapter and Win32_NetworkAdapterConfiguration WMI classes, respectively:

> wmic nic list brief > wmic nicconfig list brief

To view all available properties for those classes, replace brief with full in both commands.



Windows XP Cookbook
Windows XP Cookbook (Cookbooks)
ISBN: 0596007256
EAN: 2147483647
Year: 2006
Pages: 408

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net