Skip to content

Instantly share code, notes, and snippets.

@sharang-webonise
Created June 3, 2014 11:49
Show Gist options
  • Save sharang-webonise/abf222ae7db98ea5c4d6 to your computer and use it in GitHub Desktop.
Save sharang-webonise/abf222ae7db98ea5c4d6 to your computer and use it in GitHub Desktop.
This script connects you to the internet through Cyberoam
Replace NAME with your username and PASS with your password that you use to connect to Cyberoam.
Now add this script to your your crontab like so:
$ crontab -e
Add the following entry:
* * * * * /home/webonise/.shell_scripts/cron_jobs/webonise_cyberoam_login.sh
Replace the path with wherever the above mentioned script lies on your system.
The script will be executed every minute. It will check if you are connected to the Internet and if not it will connect you.
Basically it uses the ping command to ping the google DNS server and scrapes the output to calculate the packet loss.
Then it logs you in using the credentials you specified if you are not already connected.
PS. You need to have `curl` installed on your system for this to work.
I was too lazy to check for the existence of it in the above script!
#!/bin/bash
packet_loss=`ping -c 1 8.8.8.8 | tail -2 | head -1 | cut -d ' ' -f 6 | sed s/.$//`
if [ $packet_loss -eq 100 ]
then
query_string="mode=191&username=NAME&password=PASS&a=$(date +'%s')&producttype=0"
curl -d "${query_string}" -H "Content-Type:application/x-www-form-urlencoded" http://10.0.0.1:8090/login.xml
fi
@vishaltelangre
Copy link

Nice one! Actually I also had created a function which logs in over our cyberoam.

switch_on () {
    curl http://10.0.0.1:8090/login.xml --data "username=NAME&password=PASSWORD&mode=191&a=1385009684250&producttype=0"
}

I have to just run switch_on while startup. Didn't got caught in connection drop issue alike you, BTW.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment