Pages

Showing posts with label network adapter. Show all posts
Showing posts with label network adapter. Show all posts

Wednesday, July 6, 2011

How to display Enabled Network Adapter and their IP Address in .NET using WMI

Imports System.Management

Dim search As New ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapterConfiguration Where IPEnabled=True")
Dim info As ManagementObject
Dim strIPAddress As String = Nothing
For Each info In search.Get     

If Not (info("IPAddress")) Is Nothing Then
       Dim i As Integer
       With GrdView
         .Rows.Add()
         i = GrdView.Rows.Count - 1
         Rows(i).Cells(1).Value = info("Description").ToString
       End With



'GET THE IP ADDRESS FOR SPECIFIC NETWORK ADAPTER
Dim sql As String = "SELECT * FROM Win32_NetworkAdapterConfiguration Where IPEnabled=True
And Description='" & info("Description").ToString & "'"
  Dim searchIP As New ManagementObjectSearcher(sql)

  Dim infoIP As ManagementObject
  For Each infoIP In searchIP.Get
    strIPAddress = Join(infoIP("IPAddress"), ",")
    strIPAddress = Mid(strIPAddress, 1, InStr(strIPAddress, ",") - 1)
    GrdView.Rows(i).Cells(2).Value = strIPAddress
  Next

End If
Next