In Python, is there a way to detect whether a given network interface is up?
In my script, the user specifies a network interface, but I would like to make sure that the interface is up and has been assigned an IP address, before doing anything else.
I'm on Linux and I am root.
You can see the content of the file in /sys/class/net/<interface>/operstate. If the content is not down then the interface is up.
Python: check whether a network interface is up