Retrieving Networking Configuration Information Using Visual Basic.NET and VBScript (Page 1 of 6 )
This article explains how to retrieve “Network settings” information dynamically using Visual Basic.NET and VBScript.
A downloadable file for this article is available
here.
The sample downloadable solution (zip) is entirely developed using Visual Studio.NET 2003 Enterprise Architect on Windows Server 2003 Standard Edition. But, I am confident that it would work with other versions of Windows (which support .NET 1.1) as well.
I contributed several articles on WMI with VB.NET and VBScript previously(including a number that cover introductory or basic topics of WMI). I even contributed a series (of about six articles) on “WMI Programming on VB.NET” covering several aspects of WMI. I strongly suggest that you go through the series before going through this article.
How to list all IP addresses of a computer using Visual Basic.NET – preparing the wrapper
Before getting the information of “IPAddresses”, we need to create wrapper to store the “IPAddress” information. Let us proceed with creating a wrapper:
Public Function getNetworkInfoStructure() As DataTable
Dim dt As New DataTable
dt.Columns.Add(New DataColumn("Caption"))
dt.Columns.Add(New DataColumn("Description"))
dt.Columns.Add(New DataColumn("DHCPEnabled"))
dt.Columns.Add(New DataColumn("DHCPServer"))
dt.Columns.Add(New DataColumn("DNSDomain"))
dt.Columns.Add(New DataColumn("DNSHostName"))
dt.Columns.Add(New DataColumn("IPAddress"))
Return dt
End Function
The following method “addNetworkInfo” adds a single row based on the structure you create for the data table using the above method.
Public Sub addNetworkInfo(ByRef dt As DataTable, ByVal Caption As String, ByVal Description As String, ByVal DHCPEnabled As String, ByVal DHCPServer As String, ByVal DNSDomain As String, ByVal DNSHostName As String, ByVal IPAddress As String)
Dim dr As DataRow
dr = dt.NewRow
dr("Caption") = Caption
dr("Description") = Description
dr("DHCPEnabled") = DHCPEnabled
dr("DHCPServer") = DHCPServer
dr("DNSDomain") = DNSDomain
dr("DNSHostName") = DNSHostName
dr("IPAddress") = IPAddress
dt.Rows.Add(dr)
End Sub
At the moment, I didn’t give the subnet for the IP Address to be listed. But you can have it through “IPSubmit”. You just need to add that as part of the structure to get it listed.
Next: How to List all IPAddresses of a computer using Visual Basic.NET – the code >>
More Visual Basic.NET Articles
More By Jagadish Chaterjee