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
Listbox1.AddRow(System.GetNetworkInterface(i).IPAddress)
Next[/code]

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

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?
cheers.
B.[/quote]
You are.

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

C:\\WINDOWS\\system32>ipconfig

Windows IP Configuration

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

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:-

http://apple.stackexchange.com/questions/910/adding-a-second-ip-address-to-an-existing-network-adapter

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:
https://www.monkeybreadsoftware.net/class-networkinterfacembs.shtml

@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: https://forum.xojo.com/19289-how-to-get-local-ip-addresses