Getting Notified on “Ethernet cable plugged in” events in linux

社会主义新天地 提交于 2019-12-06 07:52:10

There are many ways to get the "UP" status of a network interface via polling, ranging from simply parsing ifconfig output, to reading the status of /proc/net/... pseudo-files.

However, for a way to be notified (i.e. not poll yourself) for such events, your best option on Ubuntu is to use the netplug package. It's not installed by default, you need to: sudo apt-get install netplug

Some documentation is here: http://manpages.ubuntu.com/manpages/lucid/man8/netplugd.8.html

To set it up you need to tweak /etc/netplug/netplugd.conf and /etc/netplug/netplug scripts. For an example of those config files check out the section "Configuring netplug" at http://natisbad.org/dyn-net/index.html

With /etc/netplug/netplug you can have your own python script called when the network goes down/up, so you can generate your kind of event for your application.

Have you looked into netplugd command, I am not sure if a python wrapper exists but it should not be hard to parse the output

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!