Python: check whether a network interface is up

前端 未结 6 447
孤城傲影
孤城傲影 2020-12-03 15:52

In Python, is there a way to detect whether a given network interface is up?

In my script, the user specifies a network interface,

6条回答
  •  情话喂你
    2020-12-03 16:18

    If the question is about checking if the cable is conencted (FreeBSD);

    [status for status in run.cmd(' /usr/local/bin/sudo ifconfig %s ' % interface).split("\t") if status.strip().startswith("status")][0].strip().endswith("active")
    

    For this, no api support so far :( ...

提交回复
热议问题