In Python, is there a way to detect whether a given network interface is up?
In my script, the user specifies a network interface,
With pyroute2.IPRoute:
from pyroute2 import IPRoute ip = IPRoute() state = ip.get_links(ip.link_lookup(ifname='em1'))[0].get_attr('IFLA_OPERSTATE') ip.close()
With pyroute2.IPDB:
from pyroute2 import IPDB ip = IPDB() state = ip.interfaces.em1.operstate ip.release()