What's new

Auto Login script for ISP

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

tron05

Occasional Visitor
Hi,

My ISP requires a login to a web page every 24 hours to enable internet access. I have done a search on this forum and count not find any related thread.

Can anyone share any script they have or guide me on a simple way to do it?
 
Hmm, depending on what that login page looks like, this one could be tricky...

Some questions so I can try to understand how this works...

  1. How do you get to the login page? Does it have a specific URL that you need to visit every 24 hours? Or does it just pop up when you try to visit some other page but you need to authenticate?
  2. What is the URL of the login page?
  3. Does it use HTTP or HTTPS?
  4. Can you reauthenticate more than once every 24 hours?
  5. Can you post the source code of the login page as an attachment?
 
Hmm, depending on what that login page looks like, this one could be tricky...

Some questions so I can try to understand how this works...

  1. How do you get to the login page? Does it have a specific URL that you need to visit every 24 hours? Or does it just pop up when you try to visit some other page but you need to authenticate? Its a URL that pops up when the 24hrs are over and any webpage i try to access redirects me to this intranet URL
  2. What is the URL of the login page?
  3. Does it use HTTP or HTTPS? its HTTP
  4. Can you reauthenticate more than once every 24 hours? Yes. I can manually log out and then login
  5. Can you post the source code of the login page as an attachment? yes. Attached

Sorry..was out for a while... And thanks for looking in.
Replied to all your queries.

Scripts attached.
1. When i need to login, i get the page Rel_bb_login.txt
- This page has a textbox to enter user id and password.
- The action part in the attachment can be identified by the action 'login.do'

2. When i am logged in and need to log out, i get the screen in attachment - Rel_bb_logout.txt
-The Action part can be identified by searching for 'logout.do'.

What i am looking for is:
1. Since its a 24hr session, the script should only run at 7AM daily from my Asus N16(with Merlin build)
2. This script should log out and then log in with my id/password and somehow confirming that it got logged in.

Appreciate any help on this or even a direction on what i should be doing...
 

Attachments

  • Rel_bb_logout.txt
    19.5 KB · Views: 444
  • Rel_bb_login.txt
    16.6 KB · Views: 558
See if running this from the router is able to log you in:
Code:
USERNAME=your_username_here \
PASSWORD=your_password_here \
HOST=reliancebroadband.co.in \
URL=/reliance/login.do?action=doLoginSubmit \
sh -c 'CONTENT="userId=$USERNAME&password=$PASSWORD"; CONTENT_LENGTH=`echo $CONTENT|wc -c`; REQUEST="POST $URL HTTP/1.0\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: $CONTENT_LENGTH\r\n\r\n$CONTENT"; echo -en $REQUEST | nc $HOST 80'
This is a single command that you can paste into an SSH session. You'll need to put your username and password in there of course...

If your username or password contain any characters that need to be URL encoded, we'll need to deal with those... See this page for a list of characters.

-Vince
 
See if running this from the router is able to log you in:
Code:
USERNAME=your_username_here \
PASSWORD=your_password_here \
HOST=reliancebroadband.co.in \
URL=/reliance/login.do?action=doLoginSubmit \
sh -c 'CONTENT="userId=$USERNAME&password=$PASSWORD"; CONTENT_LENGTH=`echo $CONTENT|wc -c`; REQUEST="POST $URL HTTP/1.0\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: $CONTENT_LENGTH\r\n\r\n$CONTENT"; echo -en $REQUEST | nc $HOST 80'
This is a single command that you can paste into an SSH session. You'll need to put your username and password in there of course...

If your username or password contain any characters that need to be URL encoded, we'll need to deal with those... See this page for a list of characters.

-Vince

Hi,
Thanks for the script. It gives a error 'Username was invalid! Please try again.'

I have entered the username and password in the scripts. They are all numbers. Can you check...
 

Attachments

  • script_log1.txt
    8 KB · Views: 520
Well, darn.

Try this:
Code:
USERNAME=your_username_here \
PASSWORD=your_password_here \
HOST=reliancebroadband.co.in \
URL=/reliance/login.do \
QUERY=?action=doLoginSubmit \
sh -c 'CONTENT="userId=$USERNAME&password=$PASSWORD"; CONTENT_LENGTH=`echo $CONTENT|wc -c`; REQUEST="POST $URL$QUERY HTTP/1.1\r\nHost: $HOST\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: $CONTENT_LENGTH\r\nReferrer: http://$HOST$URL\r\nUser-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)\r\nConnection: close\r\n\r\n$CONTENT"; echo -en "REQUEST:\r\n$REQUEST\r\n\r\n"; echo RESPONSE:; echo -en $REQUEST | nc $HOST 80'

And post the entire output (if your username and password are numbers, replace them with all zeros, but keep the length the same).

Also, did you try logging out first?

Thanks,
Vince
 
Well, darn.

Try this:
Code:
USERNAME=your_username_here \
PASSWORD=your_password_here \
HOST=reliancebroadband.co.in \
URL=/reliance/login.do \
QUERY=?action=doLoginSubmit \
sh -c 'CONTENT="userId=$USERNAME&password=$PASSWORD"; CONTENT_LENGTH=`echo $CONTENT|wc -c`; REQUEST="POST $URL$QUERY HTTP/1.1\r\nHost: $HOST\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: $CONTENT_LENGTH\r\nReferrer: http://$HOST$URL\r\nUser-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)\r\nConnection: close\r\n\r\n$CONTENT"; echo -en "REQUEST:\r\n$REQUEST\r\n\r\n"; echo RESPONSE:; echo -en $REQUEST | nc $HOST 80'

And post the entire output (if your username and password are numbers, replace them with all zeros, but keep the length the same).

Also, did you try logging out first?

Thanks,
Vince

Hi Vince,

Couldn't get through... I have been trying after i log out and ensuring that i get the log in page.

Attaching the entire output. Replaced user id and password with zeroes(number of digit is same as my actual id/pass)
 

Attachments

  • script_log2.txt
    9.9 KB · Views: 637
Hmm, the site is setting a cookie. I wonder if that has something to do with it. Try disabling cookies in your web browser and see if that breaks your ability to login from the browser...

-Vince
 
Hmm, the site is setting a cookie. I wonder if that has something to do with it. Try disabling cookies in your web browser and see if that breaks your ability to login from the browser...

-Vince

Hi Vince,

As usual, you are spot on.

-Deleted all cookies from IE
- Disabled cookies for this ISP site(from Internet options>Privacy)
- Logged out from the URL
- Tried Logging back in with the credentials

Did not allow me to log in. Gave this error: 'Username was invalid! Please try again.'
So does it mean, this cannot be automated from the router?
 
Eh, nothing's impossible. :)

Put this into something like login.sh and run it:

Code:
#!/bin/sh

USERNAME=your_username_here
PASSWORD=your_password_here
HOST=reliancebroadband.co.in
URL=/reliance/login.do
QUERY=?action=doLoginSubmit

CONTENT="userId=$USERNAME&password=$PASSWORD"
CONTENT_LENGTH=`echo $CONTENT|wc -c`

HEADERS="Host: $HOST\r\nUser-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)\r\nConnection: close\r\n"
REQUEST="GET $URL HTTP/1.1\r\n$HEADERS\r\n"
echo -en "REQUEST:\r\n$REQUEST\r\n\r\n"
echo RESPONSE:
RESPONSE=`echo -en $REQUEST | nc $HOST 80`
echo "$RESPONSE"

COOKIES=`echo "$RESPONSE"|grep -i ^Set-Cookie:|sed -e "s/Set-Cookie: \?/\1/" -e "s/;.*//"|tr -s '\r\n' \;|sed -e "s/;$//"`
HEADERS="${HEADERS}Cookie: $COOKIES\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: $CONTENT_LENGTH\r\nReferrer: http://$HOST$URL\r\n"
REQUEST="POST $URL$QUERY HTTP/1.1\r\n$HEADERS\r\n$CONTENT"                                                                                                  
echo -en "REQUEST:\r\n$REQUEST\r\n\r\n"                                                                                                                     
echo RESPONSE:                                            
echo -en $REQUEST | nc $HOST 80

This will make two HTTP requests. The first one to get any cookies and the second one will use those cookies and log in.

Definitely getting fancy for a shell script. :)
 
Eh, nothing's impossible. :)

Put this into something like login.sh and run it:

Code:
#!/bin/sh

USERNAME=your_username_here
PASSWORD=your_password_here
HOST=reliancebroadband.co.in
URL=/reliance/login.do
QUERY=?action=doLoginSubmit

CONTENT="userId=$USERNAME&password=$PASSWORD"
CONTENT_LENGTH=`echo $CONTENT|wc -c`

HEADERS="Host: $HOST\r\nUser-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)\r\nConnection: close\r\n"
REQUEST="GET $URL HTTP/1.1\r\n$HEADERS\r\n"
echo -en "REQUEST:\r\n$REQUEST\r\n\r\n"
echo RESPONSE:
RESPONSE=`echo -en $REQUEST | nc $HOST 80`
echo "$RESPONSE"

COOKIES=`echo "$RESPONSE"|grep -i ^Set-Cookie:|sed -e "s/Set-Cookie: \?/\1/" -e "s/;.*//"|tr -s '\r\n' \;|sed -e "s/;$//"`
HEADERS="${HEADERS}Cookie: $COOKIES\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: $CONTENT_LENGTH\r\nReferrer: http://$HOST$URL\r\n"
REQUEST="POST $URL$QUERY HTTP/1.1\r\n$HEADERS\r\n$CONTENT"                                                                                                  
echo -en "REQUEST:\r\n$REQUEST\r\n\r\n"                                                                                                                     
echo RESPONSE:                                            
echo -en $REQUEST | nc $HOST 80

This will make two HTTP requests. The first one to get any cookies and the second one will use those cookies and log in.

Definitely getting fancy for a shell script. :)

Initially i was trying to google and try to understand what the code does. Now- not even trying. Btw, just learnt basic unix commands to move around directories :)

Got the below message. Tried running reliancebroadband.co.in in IE and it works...

Code:
admin@RT-N16:/tmp/mnt/Elements/Router# sh login.sh
: not foundine 2:
: not foundine 8:
: not foundine 11:
REQUEST:
 HTTP/1.1ance/login.do
Host: reliancebroadband.co.in
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)
Connection: close



RESPONSE:
'c: bad address 'reliancebroadband.co.in

: not foundine 18:
: not foundine 21:
REQUEST:
 HTTP/1.1ance/login.do
Host: reliancebroadband.co.in
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)
Connection: close



RESPONSE:
'c: bad address 'reliancebroadband.co.in
admin@RT-N16:/tmp/mnt/Elements/Router#
 
Hmm, something isn't right here... Can you double-check the script file?

Maybe run "cat login.sh" and post a screenshot...
 
Hmm, something isn't right here... Can you double-check the script file?

Maybe run "cat login.sh" and post a screenshot...

Here it is...

Thanks!
 

Attachments

  • Capture.jpg
    Capture.jpg
    61.1 KB · Views: 591
OK, how did you create the login.sh file? Did you create it on your Windows computer and put it on a USB drive? If so, I think that is the problem. The file has DOS-style line endings (\r\n) instead of UNIX-style (\n).

Do this:

Code:
sed -i 's/\r//' login.sh

and try running it again.
 

Similar threads

Latest threads

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top