Run A Script When Connected To A Wireless Network In Linux

3

1

Is it possible to have a script run when I connect to a wireless network?

My university hijacks all HTTP(S) connections when you first connect to force you to log in with your university account. I've already written a script to take care of the log in, but I would like to have it run automatically when I connect to the network.

Ryan Fox

Posted 2009-08-31T02:30:35.690

Reputation: 366

What script did you write to take care of the login? I've been able to do this with lynx, but is there a better way? – Menasheh – 2017-01-03T19:44:54.187

Answers

1

I'm pretty sure the Wicd network manager can do that. You might want to check it out, I know it work on ubuntu and opesuse

alpha1

Posted 2009-08-31T02:30:35.690

Reputation: 1 638

6

Network Manager will automatically run scripts in certain directories at certain stages of network connection.

Loo in /etc/network. You'll see four directories, with self-explanatory names (given that "if" stands for "network interface"). You're looking for if-up.d. Put your script in there, name it something like 50-university-login.sh, and mark it executable.

In case you're wondering, the numbered prefixes give the scripts an order. the "default" is 50, halfway from 01 to 99.

Ryan C. Thompson

Posted 2009-08-31T02:30:35.690

Reputation: 10 085

Old answer, but this doesn't work for me (anymore). I'm trying to run a script when (wlan0) connects to a hotspot. The script parses iwconfig and works when I manually call it.

I'm on Lucid and I symlinked my script into /etc/network/if-up.d/ and it's never executed.

Any idea why? – Till – 2010-08-26T15:31:24.533

Check this link: https://wiki.ubuntu.com/OnNetworkConnectionRunScript I had to do the second part, I guess I'm not using Network Manager

– Sloy – 2013-07-22T12:56:53.283