SamuelYvon / netifaces-2

netifaces reborn
https://pypi.org/project/netifaces2/
MIT License
21 stars 7 forks source link

Way to access an interface's Name or Index on Windows #27

Closed relativityspace-jsmith closed 4 months ago

relativityspace-jsmith commented 4 months ago

Hello! I'm the dev of multicast_expert, a library that provides multicast socket functionality in Python. My library can't work without netifaces, because to do multicast subscribes you need to enumerate the interfaces on the machine and you often need to convert between an interface's index and its IP address (as there is zero consistency between the different OSs' methods of multicast subscriptions).

I've been a bit worried about the netifaces situation, so I am really grateful that you have picked up this library and are modernizing it as well. I'm working on porting multicast_expert over to use it.

However, I did run into a bit of an issue on Windows with interface indexes. On Windows, you need the interface index in order to use the IPV6_MULTICAST_IF socket option. With netifaces 1, I was getting the interface index by passing the interface's name (actually some sort of GUID) to GetAdapterIndex. Annoying to set up, but it worked. However, it looks like in netifaces2, you return the description of the interface as its name instead of the actual name field. This is much better for user experience, but breaks the method I was using.

Would it be possible to either:

The second one seems like the better option overall but I understand it would be a bit more work, so I'd really be fine with either. If you can fix this, I should be able to update multicast_expert to use netifaces2 instead of netifaces!

SamuelYvon commented 4 months ago

I have a lot of work to do (in general also) on this project for windows support. On some user's machine it completely fails in general. For now, I would keep the old netifaces for your need and I'll try to add your request.

Or, provide an API on all platforms to get the interface index for an interface?

Is the index of an interface well defined? Are they ordered deterministically?

Provide a way to get the UUID (the IP_ADAPTER_INFO Name field) from Python on Windows, so I can restore my old hack

I think that may be possible without too much hassle. I'll check over the weekend

SamuelYvon commented 4 months ago

{E5993936-7D91-44DD-84FD-55D909FF2143}

@relativityspace-jsmith Is this the type of adapter UUID you want?

SamuelYvon commented 4 months ago

On dev:

>>> import netifaces
>>> netifaces.interfaces()
['Realtek PCIe GbE Family Controller', 'Hyper-V Virtual Ethernet Adapter']
>>> netifaces.interfaces(netifaces.InterfaceDisplay.MachineReadable)
['{E5993936-7D91-44DD-84FD-55D909FF2143}', '{09E319D9-0011-4766-9769-B897BCBEF5A8}']
>>>
relativityspace-jsmith commented 4 months ago

Yeah this is what I need to make my lib work! But looking into it I also found some other stuff, working on a PR

SamuelYvon commented 4 months ago

Ok! I'll close this issue and focus on the other PR