Linux script to connect/disconnect wishnet

Standard

ISP like wishnet provides a web interface to the customers for activating/deactivating the internet connection. Hence to be connected with internet, user needs desktop/window-manager and browser. Frustrated ?  Linux has the commands to rescue you.

Login

The links may vary , at my end the login link is

http://192.168.183.201:9087/Kolkata9/WISHS/Login.jsp

After getting username / password  the links quickly redirected to

http://1.1.1.1/login1.html?a=%3F<username>%2B%2F%40&b=%3F<password>%2B%2F%40

then

http://1.1.1.1/login

and finally landed at following with active connection

http://192.168.183.201:9087/Kolkata9/WISHS/Home.jsp

I just followed all these links from command line with curl command but no success as no internet from ISP. Then I dig further with Fiddler extension and mystery disclosed. There is a cookie session.

Selection_040

Selection_039

So we have to preserve the cookie, then using the same session must pass username / password to the authentication link.

curl -sS -c wishnet.cookie http://192.168.183.201:9087/Kolkata9/WISHS/Login.jsp
curl -sS -X POST -c wishnet.cookie -d <username> -d <password> http://1.1.1.1/login

Logout

This time not Fiddler but chromium developer tools successfully discloses the correct combination.

http://192.168.183.201:9087/Kolkata9/WISHS/Home.jsp/logoutUI.do3?sessUserName=<username>

Script

Here is a script to make the life easier

#!/bin/bash
user=your_wishnet_username
pass=your_wishnet_password
login="http://192.168.183.201:9087/Kolkata9/WISHS"
login_url="$login/Login.jsp"
logout_url="$login/logoutUI.do3?sessUserName=$user"
auth_url=http://1.1.1.1/login

# -s, --silent Silent or quiet mode.
#Don't show progress meter or error messages. Makes Curl mute.
#It will still output the data you ask for, potentially even to the
#terminal/stdout unless you redirect it.
# -S, --show-error Show error. With -s, make curl show errors when they occur

connect ()
{
curl -sS -c wishnet.cookie $login_url > /dev/null
curl -sS -X POST -c wishnet.cookie -d username=$user -d password=$pass $auth_url > /dev/null
ping -c 3 gmail.com
}

disconnect ()
{
curl $logout_url
ping -c 3 gmail.com
}

case $1 in
connect)
 connect ;;
disconnect)
 disconnect ;;
esac

ping command has been included to realize the actual situation.

Operation

./wishnet connect

Selection_041.png

./wishnet disconnect

Selection_042

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s