Code for returning IP configuration data using VBScript

Source: Internet
Author: User

The WMI script used to return configuration data (similar to the information returned by the ipconfig command.
'Returning IP configuration data
'Wmi script that returns configuration data similar to that returned by ipconfig.
Strcomputer = "."
Set ob1_miservice = GetObject ("winmgmts: \" & strcomputer & "\ Root \ cimv2 ")
Set coladapters = obw.miservice. 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, 11, 2 )&":"&_
Mid (utcdate, 13, 2 ))
End Function

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.