Answered Ip-adres from networkinterface

Tijl

New member
Joined
Dec 5, 2009
Messages
1
Programming Experience
1-3
I'm building a server-appllication and i need to be able to select the correct networkinterface to start the listening events.

using the following code i put a list off all available interfaces in a menu.
VB.NET:
Imports System.Net.NetworkInformation
VB.NET:
Dim adapters As NetworkInterface() = NetworkInterface.GetAllNetworkInterfaces()
        Dim adapter As NetworkInterface
        For Each adapter In adapters
            Dim status As OperationalStatus
            status = adapter.OperationalStatus
            If status = NetworkInformation.OperationalStatus.Up Then
                AdapterToolStripMenuItem.DropDownItems.Add(adapter.Description)
                AdapterToolStripMenuItem.CheckOnClick = True
            End If
        Next adapter

After i selected a adapter i want to know wich ip-adres is bound to it.

VB.NET:
Dim adapterProperties As IPInterfaceProperties = adapter.GetIPProperties()
                With adapterProperties
                '?????
            End With

so what code, do i need to put there?
i've been searching here, but i couldn't find the answer.
 
Last edited:
If you're interested in unicast addresses:
VB.NET:
For Each ip As UnicastIPAddressInformation In adapter.GetIPProperties.UnicastAddresses
    Console.WriteLine(ip.Address.ToString)
Next
 
Back
Top