al45tair/netifaces

Type of interface?

Opened this issue · 3 comments

I'd like to be able to loop through netifaces.interfaces() and get only the ones that are ethernet, or bluetooth, wifi. Is there a way to do this currently? If not, is it planned?

EDIT: netifaces.ifaddresses().keys() gives me dict_keys([17, 2, 10]) for both ethernet and wifi, but loopback is just dict_keys([17])
Which is why I was curious if I was missing something.

https://gist.github.com/Lvl4Sword/86e73ca79bea24c9e05e35fbd1de45aa
Is a basic approach to this problem if anyone views this issue looking for a fix

Unfortunately that isn't a fix suitable for netifaces itself because not every platform has /sys/class/net.

It's possible that some suitable functionality could be added to netifaces to detect interface type; the issue is that doing so is somewhat system specific and to be useful netifaces has to cover a reasonable range of systems; it's no good offering a feature if it only works on Linux… a bare minimum is that something works on Linux, macOS and Windows, and even then ideally we'd have fallback code for generic UNIX platforms.

Sure, and I'm not recommending this as a netifaces fix. But it's definitely something that should be addressed, and this I believe is the beginning of that. I wouldn't mind working on a Python iteration of this, but I have no skills in C.