
Adapter Information Round 2
In an
earlier post getting local adapter information via the
Internet Protocol Helper (IP Helper) was discussed. The
.NET Framework version 2.0 has the
System.Net.NetworkInformation namespace that provides access to this information. For this sample I used
VB.NET, however I will try some '
blogged' tricks to see if I can get this working in
BDS® 2006 and see how it all works out.

Imports System.Net.NetworkInformation
Imports System.Net
Public Sub RetrieveLocalAdapterInformation(ByVal text As TextBox)
Dim interfaces As NetworkInterface() 'NIC
Dim netInterface As NetworkInterface ' adapter
Dim properties As IPInterfaceProperties
Dim address As PhysicalAddress
Dim ip As IPAddress
Dim ipinfo As IPAddressInformation
text.Clear()
If NetworkInterface.GetIsNetworkAvailable Then
interfaces = NetworkInterface.GetAllNetworkInterfaces
If interfaces.GetLength(0) > 0 Then
For Each netInterface In interfaces
properties = netInterface.GetIPProperties
text.AppendText(netInterface.Name & vbCrLf)
text.AppendText("Id: " & netInterface.Id.ToString & vbCrLf)
address = netInterface.GetPhysicalAddress
text.AppendText("MAC Address: " & (Microsoft.VisualBasic.IIf(address.ToString = String.Empty, "None", address.ToString)) & vbCrLf)
For Each ipinfo In properties.UnicastAddresses
text.AppendText("IP: " & ipinfo.Address.ToString & vbCrLf)
Next
For Each ip In properties.DhcpServerAddresses
text.AppendText("DHCP Server: " & ip.ToString & vbCrLf)
Next
For Each ip In properties.DnsAddresses
text.AppendText("DNS Server: " & ip.ToString & vbCrLf)
Next
text.AppendText("Type: " & netInterface.NetworkInterfaceType.ToString & vbCrLf)
text.AppendText("Operational Status: " & netInterface.OperationalStatus.ToString & vbCrLf)
text.AppendText("Speed: " & netInterface.Speed.ToString("N") & " bytes" & vbCrLf)
' XP Only
'text.AppendText("Receive Only: " & netInterface.IsReceiveOnly.ToString & vbCrLf)
' XP Only
'text.AppendText("Support Multicast: " & netInterface.SupportsMulticast.ToString & vbCrLf)
text.AppendText("Support IPv4: " & netInterface.Supports(NetworkInterfaceComponent.IPv4).ToString & vbCrLf)
text.AppendText("Support IPv6: " & netInterface.Supports(NetworkInterfaceComponent.IPv6).ToString & vbCrLf)
text.AppendText("DnsSuffix: " & properties.DnsSuffix.ToString & vbCrLf)
text.AppendText("" & vbCrLf)
Next
End If
End If
End Sub
Labels: .NET, Code, VB.NET