Diese Aufgabe stellte sich mir gerade. Im Internet fand ich zwei Lösungswege; der Weg über NetworkInformation erschien mir besser:
Imports N = System.Net.NetworkInformationModule Module1Sub Main()Dim aoAlleInterfaces() As N.NetworkInterfaceDim oInterface As N.NetworkInterface, oUnicastIpAdressInfoCollection As N.UnicastIPAddressInformationCollectionDim iAnzahl As Integer , iZaehler As Integer , oUnicastIpAdressInfo As N.UnicastIPAddressInformationConsole.WriteLine("Start" )aoAlleInterfaces = N.NetworkInterface.GetAllNetworkInterfacesFor Each oInterface In aoAlleInterfacesoUnicastIpAdressInfoCollection = oInterface.GetIPProperties().UnicastAddressesiAnzahl = oUnicastIpAdressInfoCollection.CountFor iZaehler = 0 To iAnzahl - 1oUnicastIpAdressInfo = oUnicastIpAdressInfoCollection(iZaehler)If oUnicastIpAdressInfo.Address.AddressFamily = Net.Sockets.AddressFamily.InterNetwork ThenConsole.WriteLine("Treffer" )Console.WriteLine(oUnicastIpAdressInfo.Address.ToString)End IfNextNextConsole.WriteLine("Ende" )Console.ReadKey()End SubEnd Module
Als Vorbild diente ein Beispiel von Justus Bisser. Seine Lösung ist in C# geschrieben und nutzt LINQ; zur Anschauung habe ich es aufgedröselt.
Keine Kommentare:
Kommentar veröffentlichen