Run script after connected to wifi
Hi,
is there a way to run a script after I connected or disconnected to/from a (wifi) network? I want to automate the VPN connection after I connected to certain networks.
Thanks!
Hi,
is there a way to run a script after I connected or disconnected to/from a (wifi) network? I want to automate the VPN connection after I connected to certain networks.
Thanks!
Yep.. You can run script like this:
#!/bin/bash
connection=$(/usr/lib/qt5/bin/qdbus --system net.connman /net/connman/technology/wifi net.connman.Technology.GetProperties|grep Conn|awk '{print $2}')
if [[ "$connection" == "true" ]]; then
echo "Connected to WIFI" #Do what your need.
else
echo "NOT connected !" #Do what your need.
fi
The above script only queries the current state. You could use it to poll the connection state, but that would not be ideal. Instead I suggest you listen for changes to the Connected property of the /net/connman/technology/wifi DBus path.
Aaron McCarthy ( 2014-07-03 06:53:30 +0200 )editAsked: 2014-06-27 00:03:05 +0200
Seen: 1,842 times
Last updated: Jun 27 '14