Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use vbs to return IP configuration data

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article focuses on "how to use vbs to return IP configuration data", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to use vbs to return IP configuration data.

Description information

A WMI script that returns configuration data (similar to the information returned by the IPCONFIG command).

Script code

The copy code is as follows:

'Returning IP Configuration Data

'WMI script that returns configuration data similar to that 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, 11,2) & ":" & _

Mid (utcDate, 13,2))

End Function

At this point, I believe you have a deeper understanding of "how to use vbs to return IP configuration data". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report