network interfaces.

I seem to remember being able to enumerate the interfaces on my host computer.
each interface may have one of more IP Addresses associated with it.
Does anyone know how to get a list of network interfaces and the ip addresses that are associated with each interface?

So assuming a host can have multiple interfaces each with their own ip addresses…
When you make a connection to a server it may only expect connections from a specific IP address.
So when you make a connection it would be wise to select an interface to use to establish the connection?

from the docs…

[code]Dim count As Integer
count = System.NetworkInterfaceCount

For i As Integer = 0 To count-1

Thanks Scott… So am I mistaken to believe that an interface can have more than one IP address?

well it depends on what you call an interface. a physical network card interface can have multiples by adding virtual interfaces (logical) onto the same physical one.

I am not sure if System.GetNetworkInterface(i) is the physical interfaces or the logical ones. I am going to guess logical based on their code.

[quote=209661:@Brian O’Brien]Thanks Scott… So am I mistaken to believe that an interface can have more than one IP address?
You are.

They can on windows - Here is mine showing it has two : and


Windows IP Configuration

Ethernet adapter Ethernet:
   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::b035:878:870e:a369%3
   IPv4 Address. . . . . . . . . . . :
   Subnet Mask . . . . . . . . . . . :
   IPv4 Address. . . . . . . . . . . :
   Subnet Mask . . . . . . . . . . . :
   Default Gateway . . . . . . . . . :

It appears that System.GetNetworkInterface(i) only gives the first one.

You can also add multipe IP addresses to network interfaces on Linux and OS/X, see:-

So ok… now I think I understand my confusion.

Would you call this a bug?

Is there a way to determine the interface index given an ip address?
I mean, when I connect the connection has to come for the IP address that the client is expecting it to come from or it will drop the connection. (Security)

Maybe I should shell to ifconfig or ipconfig to 'fig’ure this out?

have you checked to see if System.GetNetworkInterface(i).IPAddress doesn’t work for you? I am lazy so I wold check to see if that works as it is easy to get the IPs out of. otherwise you are parsing cli output and from O/S version to version the output can change breaking your app.

The code is in place and … well on my system I’ve only got one ip address so … not the best test eh?

Be aware that NetworkInterfaceMBS class shows more details:

@Schmitz but if it’s a bug then it should be ‘eventually’ fixed eh? :slight_smile:

it’s not a bug. I made my class for people who expected more features.

For windows: You might be able to use this one: