Descriptive information
A WMI script that returns configuration data, similar to the IPCONFIG command return information.
Scripting code
Copy Code code as follows:
' Returning IP Configuration Data
' WMI script that returns configuration the data similar to which returned by IpConfig.
StrComputer = "."
Set objWMIService = GetObject ("winmgmts:\\" & StrComputer & "\root\cimv2")
Set Coladapters = objWMIService.ExecQuery _
("SELECT * from Win32_NetworkAdapterConfiguration WHERE ipenabled = True")
n = 1
WScript.Echo
For each objadapter in Coladapters
WScript.Echo "Network Adapter" & N
WScript.Echo "================="
WScript.Echo "Description:" & objadapter.description
WScript.Echo "Physical (MAC) Address:" & objadapter.macaddress
WScript.Echo "Host Name:" & Objadapter.dnshostname
If not IsNull (objadapter.ipaddress) Then
For i = 0 to UBound (objadapter.ipaddress)
WScript.Echo "IP Address:" & Objadapter.ipaddress (i)
Next
End If
If not IsNull (objadapter.ipsubnet) Then
For i = 0 to UBound (objadapter.ipsubnet)
WScript.Echo "Subnet:" & Objadapter.ipsubnet (i)
Next
End If
If not IsNull (objadapter.defaultipgateway) Then
For i = 0 to UBound (objadapter.defaultipgateway)
WScript.Echo "Default Gateway:" & Objadapter.defaultipgateway (i)
Next
End If
WScript.Echo
WScript.Echo "DNS"
WScript.Echo "---"
WScript.Echo "DNS Servers in search order:"
If not IsNull (objadapter.dnsserversearchorder) Then
For i = 0 to UBound (objadapter.dnsserversearchorder)
WScript.Echo "" & Objadapter.dnsserversearchorder (i)
Next
End If
WScript.Echo "DNS Domain:" & objadapter.dnsdomain
If not IsNull (objadapter.dnsdomainsuffixsearchorder) Then
For i = 0 to UBound (objadapter.dnsdomainsuffixsearchorder)
WScript.Echo "DNS suffix search list:" & Objadapter.dnsdomainsuffixsearchorder (i)
Next
End If
WScript.Echo
WScript.Echo "DHCP"
WScript.Echo "----"
WScript.Echo "DHCP Enabled:" & objadapter.dhcpenabled
WScript.Echo "DHCP Server:" & Objadapter.dhcpserver
If not IsNull (objadapter.dhcpleaseobtained) Then
utcleaseobtained = objadapter.dhcpleaseobtained
strleaseobtained = WMIDateStringToDate (utcleaseobtained)
Else
strleaseobtained = ""
End If
WScript.Echo "DHCP Lease Obtained:" & strleaseobtained
If not IsNull (objadapter.dhcpleaseexpires) Then
Utcleaseexpires = Objadapter.dhcpleaseexpires
Strleaseexpires = WMIDateStringToDate (utcleaseexpires)
Else
Strleaseexpires = ""
End If
WScript.Echo "DHCP Lease Expires:" & Strleaseexpires
WScript.Echo
WScript.Echo "WINS"
WScript.Echo "----"
WScript.Echo "Primary WINS Server:" & Objadapter.winsprimaryserver
WScript.Echo "Secondary WINS server:" & Objadapter.winssecondaryserver
WScript.Echo
n = n + 1
Next
Function WMIDateStringToDate (utcdate)
WMIDateStringToDate = CDate (Mid (Utcdate, 5, 2) & "/" & _
Mid (Utcdate, 7, 2) & "/" & _
Left (Utcdate, 4) & "" & _
Mid (Utcdate, 9, 2) & ":" & _
Mid (Utcdate, 2) & ":" & _
Mid (Utcdate, 13, 2))
End Function