简体   繁体   中英

How can I monitor Wifi status for Linux

I want to write an application for monitoring the status of WIFI, for example, if Linux connects to an AP, I can get a notification for telling me the Wifi has been ready. For the system, the "iw" and "wpa_cli" commands are available. So what should I do? Create a new thread for scanning the wifi every 5 seconds? Does anyone have better solution for that? Thanks in advance.

We are currently experiencing a radical change in that part of the Linux system. You might have heard about the systemd debate? systemd will replace good old SysV Init. In this process of changes also the way to monitor network interfaces will change. While today's distros' solutions are based on scripts triggered by init (or upstart (on Ubuntu)), upcoming distros will be based on systemd scripts. I've not worked with systemd so far, but I found this documentation on the networking monitoring topic: http://www.freedesktop.org/wiki/Software/systemd/NetworkTarget/ . All distributions agreed that they will integrate systemd as fast as possible, so a future proof solution should use it.


Before systemd (until today):

On Debian/Ubuntu you can add a script to the folder /etc/network/if-up.d . Executables in that folder will be called every time an interface gets "up". Analogue to that you can also use the folders if-down.d , if-post-down.d , if-pre-up.d . Parameters like the interface id and some others will get passed to the script. On Debian/Ubuntu check man interfaces for more information.

Other distros might have their own mechanisms for that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM