Joined: 25 May 2010 Posts: 540 Location: State of Jefferson
Posted: Thu 03 Jan 2013, 01:39 Post_subject:
wpa_cli action scripts
Have you ever wanted to execute something automatically on network connect/disconnect?
If you use wpa_supplicant to connect, you can. This is most useful for properly timing a DHCP request, but there are other uses...
I gave a summary of this here (my second post, near the end of that page), but there are some possible extensions to the idea.
The basic idea is that if wpa_cli isinvoked with -a <action script>, it will execute the script with certain parameters...
Starting script (assumes a working udhcpc):
#wpa_cli invokes this on network connection/disconnect
#as $0 $IFACE CONNECTED or DISCONNECTED
case $2 in
udhcpc -i $1 -h `hostname`
Of course, this has a slight problem: it may result in multiple udhcpc instances managing the same interface. Usually this works fine, but here's how one could avoid it. I threw in some code to allow deconfiguring an interface.