ftao / python-ifcfg

Python cross-platform network interface discovery (ifconfig/ipconfig/ip)
BSD 3-Clause "New" or "Revised" License
55 stars 37 forks source link

Downed interfaces still appear in ifcfg #65

Open dupouyleo opened 2 years ago

dupouyleo commented 2 years ago

When i launch a command like : sudo ifconfig eth0 down

and after I run ifcfg.interfaces() in a new python interpreter the eth0 interface still appears. Is it an expected behavior ?

benjaoming commented 2 years ago

What do you see if you just run ifconfig from command line after sudo ifconfig eth0 down?

dupouyleo commented 2 years ago

If i run ifconfig the interface doesn't show up. But when i run ip address show the interface does show up but the flags are different from the interfaces that are not down.

In the results returned by ifcfg.interfaces() if UP is not present in the flag then it's a downed interface.

benjaoming commented 2 years ago

ifconfig is the preferred command on Linux when it exists, and ip is the fallback. So this result is a bit surprising.

The somewhat strange implementation is in src/ifcfg/__init__.py:

https://github.com/ftao/python-ifcfg/blob/0f26702f9b5e647f63c30fb94817ad3c9132b43e/src/ifcfg/__init__.py#L23-L30