![]() |
Hook when connecting to a wifi network?
I'd like to be able to have a script run automatically when I connect to a wifi network.
It's the main university one and it's one of those which wants me to give my username and password in a web page before I'm allowed proper access to the internet. The script would be easy -- it'd check which wifi network we just connected to (by SSID, for instance) and then if it matched the uni network it'd just be a simple curl job to send my username and password. (Come to think of it I haven't even checked if curl's available -- I can work around that if not.) Does something like this exist? I'm not new to Linux, I'm happy editing system configs and scripts etc. This is on my new N900. |
Re: Hook when connecting to a wifi network?
dbus-scripts allows that. Install this package, and create a file called /etc/dbus-scripts.d/wlan containing
/usr/local/bin/myscript * * com.nokia.icd status_changed * WLAN_INFRA CONNECTED And the script will run whenever you connect to a WLAN (infrastructure mode only not for ad-hoc connections). You can replace the third star with connection id of your university connection, so the script will only run when connected to university network, not to any network. There is a GUI for dbus-scripts, if you don't want to create the file by yourself, which is called dbus-scripts-settings. Both packages are available in extras-devel and in my repository (see my signature). curl is available in SDK repository, but there is also wget in extras. |
Re: Hook when connecting to a wifi network?
You'll find some discussion of this in this thread: http://talk.maemo.org/showthread.php?t=43028 and still more if you follow the link in the first post.
Please share any solution you come up with! |
Re: Hook when connecting to a wifi network?
Quote:
Edit: Aditionally to Matan's solution, you could maybe also use /etc/network/if-up.d. It seems like scripts in there are executed when connecting to a network. However, i haven't tried it myself. |
Re: Hook when connecting to a wifi network?
Quote:
You can find documentation in interfaces(5) man page. Look at "IFACE OPTIONS". |
Re: Hook when connecting to a wifi network?
I have it working.
I couldn't find iwconfig (though I didn't look very hard) and so found no way right away of getting the SSID. So I took the dbus-scripts approach. I was confused at first that the script wasn't called and tried restarting dbus and dbus-scripts. Restarting dbus gave me an error -- it was calling sort with --reverse which doesn't exist on this device. I replaced the --reverse with -r (beware, --reverse appears twice and only one of them is to do with sort) and then dbus restarted properly. I don't know if this was a necessary change. But then I lost all wifi. I double checked my scripts and they were fine. I rebooted the device and then everything was working. I had the script append all arguments to a file at first so I could check what was what and get the network ID I needed. Then I commented that line out and wrote the rest of the script. (I left the line in since it may be helpful to others.) The scripts I'm left with: /etc/dbus-scripts/wlan Code:
/home/user/isslogin.sh * * com.nokia.icd status_changed * WLAN_INFRA Code:
#!/bin/bash I generated mine by connecting to the network and then, before logging in, doing wget http://google.com and then inspecting the HTML returned. |
Re: Hook when connecting to a wifi network?
If your script is only does something for one connection, then the test is better done in dbus-scripts then in your script. Use the following line:
/home/user/isslogin.sh * * com.nokia.icd status_changed d49d3--my university network ID--3e410 WLAN_INFRA CONNECTED And the script will only be called for this connection, so you don't need the if statement in your script. dbus-scripts needs to be restarted after changing configuration - the easiest way is to run (as root) killall dbus-scripts . It is then restarted automatically by upstart. |
Re: Hook when connecting to a wifi network?
Yeah, I realized I could put the logic in the dbus script -- I just thought I'd leave myself flexibility in case I wanted to do other things for other networks or events. Thanks for your help.
|
Re: Hook when connecting to a wifi network?
I was doing some thing very similar and someone suggest me to don't use "--no-check-certificate".
So you can try with : "--ca-directory=/etc/certs/common-ca/" instead. In my case, I was not using dbus but an /etc/if-up.d/ script. Regards, |
Re: Hook when connecting to a wifi network?
What do I need to put in to the dbus-script to excute a script on gprs connect and disconnect?
EDIT: Figured it out, instead of: Code:
/some/script.sh * * com.nokia.icd status_changed * WLAN_INFRA Code:
/some/script.sh * * com.nokia.icd status_changed * GPRS |
All times are GMT. The time now is 16:18. |
vBulletin® Version 3.8.8