Jump to content

How to control router WebUI


Recommended Posts

I use _IECreate to open router webui.
I want to click the "AP" and "Wireless SSID".
After login ,I use _IETagNameAllGetCollection to find "div".
And show msgbox innerText information is "Username"、"Password".
It look lick stay at login page.
How do i do to find "AP" Obj ?

Can someone help me ?

My autoit code:

#include <IE.au3>

Local $oUser, $oPass, $oSubmit
Local $oItem_AP
Local $sUser = "admin"
Local $sPass = "admin"
Local $url = "192.168.50.1"
Local $oIE = _IECreate($url, 1)

_IELoadWait($oIE)

$oInputs = _IETagNameGetCollection($oIE, "input")
for $oInput in $oInputs
    if (Not isObj($oUser))   And $oInput.type = "text" And $oInput.name = "username" Then $oUser = $oInput
    if (Not isObj($oPass))   And $oInput.type = "password" And $oInput.name = "password" Then $oPass = $oInput
    if isObj($oUser) And isObj($oPass) then exitloop
Next
$oUser.value = $sUser
$oPass.value = $sPass

$oButtons = _IETagNameGetCollection($oIE, "button")
for $oButton in $oButtons
    ;if (Not isObj($oSubmit)) And String($oButton.tabindex) = "3" Then $oSubmit = $oButton
    if (Not isObj($oSubmit)) And $oButton.classname = "submit_action" Then $oSubmit = $oButton
    if isObj($oSubmit) then exitloop
Next
_IEAction($oSubmit, "click")

Sleep(5000)

$oElements = _IETagNameAllGetCollection ($oIE)
For $oElement In $oElements
if $oElement.tagname = "div" then msgbox(0, "", $oElement.innerText)
Next

Login page:

<form name="login_form" method="post">
<input name="func" type="hidden" value="login">
<div id="login_box">
    <div style="font-weight: bold;">Login</div>
    <div>
        Username:<br>
        <input name="username" tabindex="1" class="text_box" type="text" autocapitalize="off">
    </div>
    <div>
        Password:<br>
        <input name="password" tabindex="2" class="text_box" type="password" autocomplete="off">
    </div>
    <button tabindex="3" class="submit_action" type="button">Login</button>
    <div class="smart_status" id="smart_status" style="display: none;"></div>
    <div class="company">Copyright © <span id="company_name_text">Pepwave</span>. All rights reserved.</div>
</div>
</form>

Next page after login:

<div class="top_menu_panel" style="text-align: left;">
<div class="top_menu_panel" style="width: 1024px;">
<div id="top_menu" style="width: 994px; float: left;">
<div class="top_menu_logo" style='background: url("connicon.cgi?type=top_logo") no-repeat;'>&nbsp;</div>
<div class="menu_item menu_selected">Dashboard</div>
<div class="menu_item menu_action">Network</div>
<div class="menu_item menu_action">Advanced</div>
<div class="menu_item menu_action">AP</div>
<div class="menu_item menu_action">System</div>
<div class="menu_item menu_end menu_action menu_status">Status</div>
<div class="menu_item menu_end menu_apply">Apply Changes</div></div>
</div>
</div>

 

Link to comment
Share on other sites

FWIW, your login code could likely be greatly simplified. Try this:

$oForm = _IEFormGetObjByName($oIE, "login_form")
$oUser = _IEFormElementGetObjByName($oForm, "username")
$oPass = _IEFormElementGetObjByName($oForm, "password")

_IEFormElementSetValue($oUser, $sUser)
_IEFormElementSetValue($oPass, $sPass)
_IEFormSubmit($oForm)

 

Link to comment
Share on other sites

To find the correct next element, you could try something like:

$oDivs = _IETagNameGetCollection($oIE, "div")

For $oDiv In $oDivs
    If $oDiv.innerText = 'AP' Then
        _IEAction($oDiv, 'click')
        ExitLoop
    EndIf
Next

If that doesn't work, then I suggest that you save the entire HTML page to a file and post it here.

Link to comment
Share on other sites

On 2017/4/7 at 7:06 PM, Danp2 said:

To find the correct next element, you could try something like:

$oDivs = _IETagNameGetCollection($oIE, "div")

For $oDiv In $oDivs
    If $oDiv.innerText = 'AP' Then
        _IEAction($oDiv, 'click')
        ExitLoop
    EndIf
Next

If that doesn't work, then I suggest that you save the entire HTML page to a file and post it here.

Thanks for your help.

In this loop, The $oDiv.innerText is show "0".

I try the other method : 

  After login and staying at AP page (manual operation), then run  loop.

  It still show "0". And no enable click event.

HTML_1.txt

HTML_2.txt

2017-04-10_115230.png

Link to comment
Share on other sites

22 hours ago, Abbie said:

Thanks for your help.

In this loop, The $oDiv.innerText is show "0".

I try the other method : 

  After login and staying at AP page (manual operation), then run  loop.

  It still show "0". And no enable click event.

HTML_1.txt

HTML_2.txt

2017-04-10_115230.png

I find a viable method, but i don't know why ...

After login, i use _IEDocReadHTML to check is at second page.

And must be show one MsgBox (show anything).

Then ReadHTML will be change to second page ...

If no show one MsgBox, ReadHTML have been staying login page.

#include <IE.au3>

Run("WebUI_Login.exe", "", @SW_SHOWMAXIMIZED)
WinWait("Web Admin | Welcome", "", 10)

Local $Next = Call("WebUI_ReadHTML")
While $Next = 0
    Sleep(1000)
    $Next = Call("WebUI_ReadHTML")
WEnd
Call ("WebUI_SetWireless")
Exit

Func WebUI_ReadHTML()
    Local $oIE = _IEAttach("Web Admin","title")
    $source = _IEDocReadHTML ($oIE)
    MsgBox(0,"ReadHTML","Test")
    If StringInStr($source,"refresh") Then
        Return 1
    Else
        Return 0
    EndIf
EndFunc

Func WebUI_SetWireless()
    Local $oIE = _IEAttach("Web Admin","title")
    $oDivs = _IETagNameGetCollection($oIE, "div")
    For $oDiv In $oDivs
        If $oDiv.innerText = 'AP' Then
            _IEAction($oDiv, 'click')
            ExitLoop
        EndIf
    Next
    $olis = _IETagNameGetCollection($oIE, "li")
    For $oli In $olis
        If $oli.innerText = 'Wireless SSID' Then
            _IEAction($oli, 'click')
            ExitLoop
        EndIf
    Next
EndFunc

 

Edited by Abbie
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...