Enumerate Network Adapters
'
' base on C# code originally posted by Willy Denoyette
' http://groups.google.com/groups?selm=eeeD%24NrxAHA.2188%40tkmsftngp02
'
Option Strict On
Option Explicit On
Imports System
Imports System.Management
Public Class ConsoleApp
Shared Sub Main
Network.EnumNetworkAdapters()
End Sub
End Class
Public Class Network
Public Shared Sub EnumNetworkAdapters()
Dim query as ManagementObjectSearcher = new ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapterConfiguration")
Dim queryCollection as ManagementObjectCollection = query.Get()
Dim mo as ManagementObject
Dim s as String
for each mo in queryCollection
Console.WriteLine( "'{0}'", mo.ClassPath)
Console.WriteLine( "'{0}'", mo.Options)
Console.WriteLine( "Index '{0}'", mo("Index"))
Console.WriteLine( "Description '{0}'", mo("Description"))
Console.WriteLine( "MacAddress '{0}'", mo("MacAddress"))
if(CType(mo("IPEnabled"), Boolean) = true)
dim addresses() as string = CType(mo("IPAddress"), String())
dim subnets() as string = CType(mo("IPSubnet"), String())
Console.WriteLine( "DNS Host '{0}'", mo("DNSHostName"))
Console.WriteLine( "DNS Domain '{0}'", mo("DNSDomain"))
for each s in addresses
Console.WriteLine( "IP Address '{0}'", s)
next
for each s in subnets
Console.WriteLine( "IP Subnet '{0}'", s)
next
end if
next
End Sub
End Class