Sign in to follow this  
Followers 0
machalla

Linksys Router Authentication Problem - IE

15 posts in this topic

#1 ·  Posted (edited)

Hi All,

Pardon me if this should be blindingly obvious but I don't seem to have made much progress despite searching round the forums here. Any advice on this would be helpful.

I am putting together a script that will automatically make some changes to a Linksys wireless router. I'll be putting a GUI in front of it for ease of use eventually.

At the moment I am stuck literally on step 1.

I open an Internet Explorer page with the routers ip in it. This immediately brings up an authentication window in IE. I want to automatically log the user in with no user interaction.

Based on some searching around here I tried to check that the authentication window exists and then attempt to send keys to it to enter in the login details (as per the code below). I am not sure if this is really the correct way to go on this but currently its the nearest to a working solution I've got.

I found that the Authenticate function works if I open IE manually at the routers ip address and then run the function once the authenticate window is displayed. If I attempt to programmatically open the IE window and then run the authenticate function (as per the script below) the authenticate window will just sit there waiting.

I found some posts that might be related to my issue but I can't figure it out based on these so far.

http://www.autoitscript.com/forum/index.ph...462&hl=NTLM

http://www.autoitscript.com/forum/index.ph...677&hl=ntlm

http://www.autoitscript.com/forum/index.ph...+authentication

Suggestions would be very welcome. Thanks.

Modified the script to use a whle loop.

CODE
#include <IE.au3>

$str_ip_address = "192.168.1.1"

Func Authenticate()

;Connect to

$title = "Connect to " & $str_ip_address

;30 Seconds in miliseconds

$timeout = 30000

$Timer = TimerInit()

While WinExists($title)

;To prevent infinite loop provide a breakout after the defined timeout period

If TimerDiff($Timer) > $Timeout Then ExitLoop

$handle = WinGetHandle($title)

WinActivate($title)

;Enter Password

;Send("admin")

;Tab to the password field as the username is blank

Send("{TAB}")

;Enter Password

Send("mYpASS")

;Tab to the Ok button and press Enter

Send("{TAB}")

Send("{TAB}")

Send("{ENTER}")

ExitLoop

WEnd

EndFunc

;Open a browser window with the router ip address

$oIE = _IECreate($str_ip_address)

;Wait for IE to finish loading

_IELoadWait ($oIE)

Authenticate()

Edited by machalla

Share this post


Link to post
Share on other sites



Is something in the dialogue if you've used the function "Authenticate" or is it just blank ?

Share this post


Link to post
Share on other sites

Is something in the dialogue if you've used the function "Authenticate" or is it just blank ?

No, nothing appears in the dialogue at all unfortunately.

If I run the authenticate function separately it will enter the password in the password field and press the ok button successfully.

Share this post


Link to post
Share on other sites

I think I see your problem. You have no while loop. It checks for the window and if it doesn't find it then the program simply exits. Try adding an Else to your loop to wait until the window is active/visible then go through with your function.

Share this post


Link to post
Share on other sites

I think I see your problem. You have no while loop. It checks for the window and if it doesn't find it then the program simply exits. Try adding an Else to your loop to wait until the window is active/visible then go through with your function.

Thanks for your suggestion. It was a good point. Unfortunately it hasn't solved my problem though. I've looked at it further and what seems to be happening is the ie window is opening, then the authenthication popup appears. This then pauses my script!

If I open an IE window first then run the authenticate function itself, I get a successful login.

I feel I am missing something obvious here. I have to figure out how to stop my script being paused.

Again any suggestions would be welcome. Thanks for the help so far.

Share this post


Link to post
Share on other sites

See the 2nd example for _IEAction and try the technique. A popup can hold control in the browser and prevent control from returning to AutoIt after invoking a COM method on the browser.

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

No, that doesn't works with IE as of more recent years (based on my trawls through the forum searching for a solution).

I am trying to figure out how to make it work with a controlsend as per Dales suggestion.

Thanks.

Share this post


Link to post
Share on other sites

I cannot get this to work due to the script pausing. As Dale mentioned it seems as if control is never returned to the auto-it script.

The only alternative I can think of is to run an alternate login script before the browser is invoked in the script that opens and manipulates the browser.

The alternate script would just sit there and wait for the login screen to appear then enter in the required details. It seems needlessly convoluted to do it this way though so any other ideas on this would be welcome before I have to go down that route. Thanks.

Share this post


Link to post
Share on other sites

I don't believe the function _IELoadWait will ever work in this setup, because the site is still "loading" when you get a prompt for username and password. Look at the status bar when trying to access the secure page.

Share this post


Link to post
Share on other sites

I don't believe the function _IELoadWait will ever work in this setup, because the site is still "loading" when you get a prompt for username and password. Look at the status bar when trying to access the secure page.

No it won't but its irrelevant as the problem is that the script just sits there due to the focus being lost to the username and password popup/dialog. As far as I can see this is a .htaccess protected login.

I think this is the nearest post to mine with a similar problem.

http://www.autoitscript.com/forum/index.ph...462&hl=NTLM

The status bar responds with "Web site found. Waiting for reply...". while the script stays paused in the background until I hit the cancel button on the popup.

Share this post


Link to post
Share on other sites

I'm not sure I understand what you mean by irrelevant.

First you can't use the function _IECreate without setting $f_wait to 0.

Second you can't use the function _IELoadWait because the page is never loaded.

You would be in a loop forever waiting for the page to load.

Share this post


Link to post
Share on other sites

So does the authentication box come up when you simply open the url with _IECreate? If so, my suggestion was wrong,

In that case, what you want to do is:

Run(@ProgramFilesDir & "\Internet Explorer\iexplore.exe " & $str_ip_address)

Then use WinWait with a timeout looking for the login box... deal with it if it appears using normal AutoIt Win* functions.

Once you have dealt with the login box or know that it is not going to appear, use _IEAttach to gain control of the newly created browser.

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

I'm not sure I understand what you mean by irrelevant.

First you can't use the function _IECreate without setting $f_wait to 0.

Second you can't use the function _IELoadWait because the page is never loaded.

You would be in a loop forever waiting for the page to load.

@scriptjunkie

Hi sorry if that sounded brusque. I've been playing around with the script and have removed the _IELoadWait in the process of testing it so I know that wasn't the issue. You are correct about the code above though. Thanks.

@DaleHohm

Dale, thanks for the response. Yes the authentication window does appear when I use _IECreate. Sorry, I didn't make that clear. Your solution sounds like it will do the job perfectly. Thats a much better solution than using a separate script or exe. Thanks again.

Share this post


Link to post
Share on other sites

Updated solution based on Dales suggestion. Can probably be improved but the basic idea is there for anyone who comes across this problem.

CODE
#include <IE.au3>

$str_ip_address = "192.168.1.1"

Func Authenticate()

;Connect to

$title = "Connect to " & $str_ip_address

;Wait up to 30 seconds for the login dialog to appear

WinWait($title, "", 30)

$handle = WinGetHandle($title)

WinActivate($title)

;Enter Username

;Send("admin")

;Tab to the password field as the username is blank

Send("{TAB}")

;Enter Password

Send("mYpass")

;Tab to the Ok button and press Enter

Send("{TAB}")

Send("{ENTER}")

EndFunc

;Open a browser window with the router ip address

Run(@ProgramFilesDir & "\Internet Explorer\iexplore.exe " & $str_ip_address)

Authenticate()

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0