Jump to content

Help with a script to reconnect the router


Recommended Posts

I am making a script to reconnect my public ip (the external one). In order to do that, I access my router with the explorer. The problem is that I can't get a reference to the disconnect button. Seeing the source code with IETab, it seems that it's inside a table inside a frame but the function _IEIsFrameSet says there aren't any frames. However, the help file also says that if the function returns false and we know there are frames, it's because they're iframes. But if so, shouldn't they have the <IFRAME> tag and not the <FRAME> one? Anyway, I tried with _IEFrameGetCollection and it returned Warning from function _IEFrameGetObjByName, $_IEStatus_NoMatch (No Frames found). However, in the code I will put next you will see that there are 2 frames ¿?

I also tried seeing the forms with IETab and obtain them by name but I received this error: Error from function _IEFormGetObjByName, $_IEStatus_InvalidDataType. Finally, I tried to obtain the collection of INPUT tags and I received this error: Error from function _IETagNameGetCollection, $_IEStatus_InvalidDataType. How can I click the disconnect button?

This is the code of the disconnect button:

<INPUT class=btnl onclick=preSubmit(this.form,4); type=button value=Disconnected name=rnew>

This is the source code of my router:

<HTML><HEAD><TITLE>Router Setup</TITLE></HEAD><FRAMESET border=0 frameSpacing=0 rows=0,* frameBorder=NO><FRAME name=transparent><FRAME name=main src="sys_status.htm"></FRAMESET></HTML>

Now, if I go to my-router-url/sys_status.htm this is the source code (I edited some data just in case):

<HTML><HEAD><TITLE>System | Status</TITLE>
    <META http-equiv=Pragma content=no-cache>
    <META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
    <script language=Javascript src="utils.js"></SCRIPT>

    <script language=Javascript src="spec.js"></SCRIPT>

    <script language=Javascript>

    var conType=new Array("Static IP","Dynamic IP","PPPoE","PPTP","L2TP","DHCP Proxy");
    var state=new Array("Disable","Enabled");
    var conStat=new Array("Disconnected", "Connected", "Connecting");





    cableDSL="1" ;
    wanIP="1**.**.1*0.**" ;
    subMask="************" ;
    gateWay="***********" ;
    dns1="************" ;
    dns2="2************" ;
    dname="" ;
    conntime="25049" ;
    conTypeIdx="3" ;
    ipAddr="***********" ;
    gateSubMsk="*************";
    dhcpServer="1";
    firewall="1"; 
    NAT="1";
    run_code_ver="V"+"**********";
    boot_code_ver="V"+"********";
    hw_ver="V"+"*************";
    hw_sn="***********************";
    lan_mac="**************";
    wan_mac="***************";
    clients="2";
    uptime="1304986";
    curtime="1280066729";
    rmtime="0";



    sData = new Array(
    "0","0","7/25/2010","14:5:29","","","",""
    );

    function preSubmit(f,idx) {   
       var f=document.frmSetup;
       

       
       f.action.value=idx
       f.submit() ;
           
    }
    function init(f)
    {
    }
    </SCRIPT>
    <LINK href="style.css" type=text/css rel=stylesheet></HEAD>
    <BODY vLink=#000000 aLink=#000000 link=#000000 leftMargin=0 topMargin=0 onload=init(document.frmSetup); MARGINWIDTH="0" MARGINHEIGHT="0">
    <script>pageHead();</SCRIPT>

    <TABLE height=106 cellSpacing=0 cellPadding=0 width="100%" bgColor=#142a84>
    <TBODY>
    <TR>
    <TD>
    <TR>
    <TD vAlign=center bgColor=#142a84 colSpan=13 height=79>
    <TABLE cellSpacing=0 cellPadding=0 width=204 border=0>
    <TBODY>
    <TR>
    <TD width=48></TD>
    <TD><IMG height=58 src="images/name.jpg" border=0></TD></TR></TBODY></TABLE></TD></TR></TD></TR>
    <TR>
    <TD>
    <TABLE cellSpacing=0 width="100%" bgColor=#465f88>
    <TBODY>
    <TR class=menu1>
    <TD width=20 height=27></TD>
    <TD><A href="wizard.htm">&nbsp;Wizard&nbsp;</A></TD>
    <TD>&nbsp;System&nbsp;</TD>
    <TD><A href="wan_mode.htm">&nbsp;WAN&nbsp;</A></TD>
    <TD><A href="lan_dhcps.htm">&nbsp;LAN&nbsp;</A></TD>
    <TD><A href="nat_vserv.htm">&nbsp;NAT&nbsp;</A></TD>
    <TD><A href="fw_opt.htm">&nbsp;Firewall&nbsp;</A></TD>
    <TD><A href="rt_table.htm">&nbsp;Routing&nbsp;</A></TD>
    <TD><A href="upnp_config.htm">&nbsp;UPnP&nbsp;</A></TD>
    <TD><A href="ddns_config.htm">&nbsp;DDNS&nbsp;</A></TD>
    <TD><A href="javascript:preLogout();">&nbsp;Logout</A></TD>
    <TD width="40%">&nbsp;</TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>
    <TABLE>
    <TBODY>
    <TR>
    <TD class=title1 height=40>System Settings</TD></TR></TBODY></TABLE>
    <HR width="100%" SIZE=1>

    <TABLE height=300>
    <TBODY>
    <TR>
    <TD vAlign=top width=150>
    <TABLE class=menu2 cellSpacing=0 cellPadding=3 width="100%">
    <TBODY>
    <TR>
    <TD width=16 height=12></TD>
    <TD noWrap>&nbsp;System Status</TD></TR>
    <TR>
    <TD width=16 height=12></TD>
    <TD noWrap>&nbsp;<A href="sys_name.htm">System Settings</A></TD></TR>
    <TR>
    <TD width=16 height=12></TD>
    <TD noWrap>&nbsp;<A href="sys_admin.htm">Administrator Settings</A></TD></TR>
    <TR>
    <TD width=16 height=12></TD>
    <TD noWrap>&nbsp;<A href="sys_upgrade.htm">Firmware Upgrade</A></TD></TR>
    <TR>
    <TD width=16 height=12></TD>
    <TD noWrap>&nbsp;<A href="sys_config.htm">Configuration Tools</A></TD></TR>
    <TR>
    <TD width=16 height=12></TD>
    <TD noWrap>&nbsp;<A href="sys_log.htm">System Log</A></TD></TR></TBODY></TABLE></TD>
    <TD style="BORDER-LEFT: #c0c0c0 2px dashed" width=2>&nbsp;</TD>
    <TD vAlign=top>
    <TABLE width=450>
    <TBODY>
    <TR>
    <TD class=title2 noWrap>System Status</TD>
    <TD align=right><INPUT class=btn onclick='doHelp("status")' type=button value=" Help "></TD></TR></TBODY></TABLE>
    <FORM name=frmSetup action=do_cmd.htm method=post><INPUT type=hidden value=WAN_CON name=CMD> <INPUT type=hidden value=sys_status.htm name=GO> <INPUT type=hidden name=action>
    <TABLE class=text1 cellSpacing=2 cellPadding=3 width="75%">
    <TBODY>
    <TR>
    <TD class=title3>INTERNET</TD>
    <TD align=right><INPUT class=btn onclick=location=cPage type=button value=Refresh td <> </TD>
    <TR>
    <TD class=item1 width="30%">Cable/DSL</TD>
    <TD class=value1 width="40%">
    <script>document.write(conStat[cableDSL])</SCRIPT>
    Connected </TD></TR>
    <TR>
    <TD class=item1>WAN IP</TD>
    <TD class=value1>
    <script>document.write(wanIP)</SCRIPT>
    190.64.150.72 </TD></TR>
    <TR>
    <TD class=item1>Subnet Mask</TD>
    <TD class=value1>
    <script>document.write(subMask)</SCRIPT>
    255.255.255.255 </TD></TR>
    <TR>
    <TD class=item1>Gateway</TD>
    <TD class=value1>
    <script>document.write(gateWay)</SCRIPT>
    200.40.22.2 </TD></TR>
    <TR>
    <TD class=item1>DNS</TD>
    <TD class=value1>
    <script>document.write(dns1)</SCRIPT>
    200.40.220.245 </TD></TR>
    <TR>
    <TD class=item1>Secondary DNS</TD>
    <TD class=value1>
    <script>document.write(dns2)</SCRIPT>
    200.40.30.245 </TD></TR>
    <TR>
    <TD class=item1>Domain Name</TD>
    <TD class=value1>
    <script>document.write(dname)</SCRIPT>
    </TD></TR>
    <TR>
    <TD class=item1>Connection Type</TD>
    <TD class=value1>
    <script>document.write(conType[conTypeIdx-1])</SCRIPT>
    PPPoE </TD></TR>
    <script>
          if ((conTypeIdx==2)||(conTypeIdx==3)||(conTypeIdx==4)||(conTypeIdx==5))
          {
               document.write("<tr><td class=item1>Connection Time</td>");
              document.write("<td class=value1>");
              document.write(timeStr(conntime));
              document.write("</td></tr>");
          } 
          </SCRIPT>

    <TR>
    <TD class=item1>Connection Time</TD>
    <TD class=value1>06:57:29</TD></TR>
    <script>
          if (conTypeIdx==2)
          {
               document.write("<tr><td class=item1>Remaining Time</td>");
              document.write("<td class=value1>");
              document.write(timeStr(rmtime));
              document.write("</td></tr>");
          } 
          </SCRIPT>

    <TR>
    <script>
            if (conTypeIdx==2) {
               document.write("<td><input type=button class=btn value=Release name=rlease onclick=preSubmit(this.form,1);></td>");
               document.write("<td><input type=button class=btn value=Renew name=rnew onclick=preSubmit(this.form,2);></td>");
            }
            else if (conTypeIdx == 3) {
               document.write("<td><input type=button class=btnl value=Connection name=rlease onclick=preSubmit(this.form,3);></td>");
               document.write("<td><input type=button class=btnl value=Disconnected name=rnew onclick=preSubmit(this.form,4);></td>");
            }
            else if (conTypeIdx == 4) {
               document.write("<td><input type=button class=btnl value=Connection name=rlease onclick=preSubmit(this.form,5);></td>");
               document.write("<td><input type=button class=btnl value=Disconnected name=rnew onclick=preSubmit(this.form,6);></td>");
            }
            else if (conTypeIdx == 5) {
               document.write("<td><input type=button class=btnl value=Connection name=rlease onclick=preSubmit(this.form,7);></td>");
               document.write("<td><input type=button class=btnl value=Disconnected name=rnew onclick=preSubmit(this.form,8);></td>");
            }
          </SCRIPT>

    <TD><INPUT class=btnl onclick=preSubmit(this.form,3); type=button value=Connection name=rlease></TD>
    <TD><INPUT class=btnl onclick=preSubmit(this.form,4); type=button value=Disconnected name=rnew></TD></TR>
    <TR>
    <TD colSpan=2></TD></TR>
    <TR>
    <TD class=title3 colSpan=2>GATEWAY</TD></TR>
    <TR>
    <TD class=item1>IP Address</TD>
    <TD class=value1>
    <script>document.write(ipAddr)</SCRIPT>
    *********************** </TD></TR>
    <TR>
    <TD class=item1>Subnet Mask</TD>
    <TD class=value1>
    <script>document.write(gateSubMsk)</SCRIPT>
    ******************* </TD></TR>
    <TR>
    <TD class=item1>DHCP Server</TD>
    <TD class=value1>
    <script>document.write(state[dhcpServer])</SCRIPT>
    Enabled </TD></TR>
    <TR>
    <TD class=item1>NAT</TD>
    <TD class=value1>
    <script>document.write(state[NAT])</SCRIPT>
    Enabled </TD></TR>
    <TR>
    <TD class=item1>Firewall</TD>
    <TD class=value1>
    <script>document.write(state[firewall])</SCRIPT>
    Enabled </TD></TR>
    <TR>
    <TD colSpan=2></TD></TR>
    <TR>
    <TD class=title3 colSpan=2>INFORMATION</TD></TR><!--
          <tr>
            <td class=item1>Current Time</td>
            <td class=value1>
             <script language=Javascript>
                    document.write(curtime);
                </SCRIPT>
            </td>
          </tr>
    -->
    <TR>
    <TD class=item1>System Up Time</TD>
    <TD class=value1>
    <script language=Javascript>
                    document.write(timeStr(uptime));
                </SCRIPT>
    15 days 02:29:46 </TD></TR>
    <TR>
    <TD class=item1>System Date</TD>
    <TD class=value1>
    <script language=Javascript>
                    document.write(sData[2]+" "+sData[3]);
                </SCRIPT>
    7/25/2010 14:5:29 </TD></TR>
    <TR>
    <TD class=item1>Connected Clients</TD>
    <TD class=value1>
    <script language=Javascript>
                    document.write( clients );
                </SCRIPT>
    2 </TD></TR>
    <TR>
    <TD class=item1>Runtime Code Version</TD>
    <TD class=value1>
    <script language=Javascript>
                    document.write( run_code_ver );
                </SCRIPT>
    V2.1.2.94 </TD></TR>
    <TR>
    <TD class=item1>Boot Code Version</TD>
    <TD class=value1>
    <script language=Javascript>
                    document.write( boot_code_ver );
                </SCRIPT>
    V0.1.5.9 </TD></TR>
    <TR>
    <TD class=item1>LAN MAC Address</TD>
    <TD class=value1>
    <script language=Javascript>
                    document.write( lan_mac );
                </SCRIPT>
    ********************** </TD></TR>
    <TR>
    <TD class=item1>WAN MAC Address</TD>
    <TD class=value1>
    <script language=Javascript>
                    document.write( wan_mac );
                </SCRIPT>
    ******************* </TD></TR></TBODY></TABLE>
    <script>pageTail(' ');</SCRIPT>

    <TABLE width="95%">
    <TBODY>
    <TR>
    <TD height=40>&nbsp;</TD></TR>
    <TR>
    <TD align=right height=40></TD></TR></TBODY></TABLE></FORM></TD></TR></TBODY></TABLE></BODY></HTML>

And here it's the code with the last thing I tried: To obtain all the 'INPUT' tags in order to select the one that has 'rnew' in its name and it returned Error from function _IETagNameGetCollection, $_IEStatus_InvalidDataType ==> Variable must be of type "Object". But didn't _IETagNameGetCollection return 'a collection object' ??

#include <IE.au3>
    #include <INet.au3>

    Const $urlrouter = the url of my router
    Const $user = user
    Const $password = password

    $ventana = _IECreate($urlrouter,0,1,0)
    WinWaitActive("Conectarse a "&$urlrouter)
    Send($user)
    Send("{TAB}")
    Send($password)
    Send("{ENTER}")
    _IELoadWait($ventana)

    $ventana2 = _IENavigate ($ventana,"$urlrouter"&/sys_status.htm")
    _IELoadWait($ventana2)
    $obotons = _IETagNameGetCollection($ventana2,"INPUT")
    For $oboton In $obotons
       If $oboton.name = "rnew" then _IEAction($oboton,"click")
    Next
    _IELoadWait($ventana2)

    ;From now on it gives errors, the rest of the code is to click the 'OK' button, connect and logout from the router

    $frame = _IEFrameGetObjByName($ventana,"main")
    $obotons = _IETagNameGetCollection($frame,"INPUT")
    For $oboton In $obotons
       _IEAction($oboton,"click")
    Next
    _IELoadWait($ventana)
    $frame = _IEFrameGetObjByName($ventana,"main")
    $obotons = _IETagNameGetCollection($frame,"INPUT")
    For $oboton In $obotons
       If $oboton.name = "rlease" Then _IEAction($oboton,"click")
    Next
    _IELoadWait($ventana)
    $frame = _IEFrameGetObjByName($ventana,"main")
    $obotons = _IETagNameGetCollection($frame,"INPUT")
    For $oboton In $obotons
       _IEAction($oboton,"click")
    Next
    _IELoadWait($ventana)
    $frame = _IEFrameGetObjByName($ventana,"main")
    $obotons = _IETagNameGetCollection($frame,"A")
    For $oboton In $obotons
       If $oboton.href = "javascript:preLogout();" Then _IEAction($oboton,"click")
    Next

Thanks for ANY help :blink::P;)

Link to comment
Share on other sites

That worked :P I got confused because of the frames but it was simpler that what I thought. Here is the code so far:

#include <IE.au3>
        #include <INet.au3>

        Const $urlrouter = "";the url of the router without http://
        Const $user = "usuario"
        Const $password = "contraseña"

        $ventana = _IECreate("http://"&$urlrouter&"/sys_status.htm",0,1,0)
        WinWait("Conectarse a "&$urlrouter)
        ControlSend("Conectarse a "&$urlrouter,"","[CLASS:Edit; INSTANCE:2]",$user)
       ControlSend("Conectarse a "&$urlrouter,"",1005,$password)
        ControlClick("Conectarse a "&$urlrouter,"Aceptar",1)
        _IELoadWait($ventana)

       $disconnectObj = _IEGetObjByName($ventana,"rnew")
        _IEAction($disconnectObj,"click")
       _IELoadWait($ventana)
       $oinputtags = _IETagNameGetCollection($ventana,"INPUT")
       For $oinputtag In $oinputtags
            If $oinputtag.value = " Continue " Then _IEAction($oinputtag,"click")
       Next
       _IELoadWait($ventana)
       $connectObj = _IEGetObjByName($ventana,"rlease")
       _IEAction($connectObj,"click")
       _IELoadWait($ventana)
        $oinputtags = _IETagNameGetCollection($ventana,"INPUT")
       For $oinputtag In $oinputtags
            If $oinputtag.value = " Continue " Then _IEAction($oinputtag,"click")
       Next
       _IELoadWait($ventana)
       _IENavigate($ventana,"javascript:preLogout();")
       ;$ohrefs = _IETagNameGetCollection($ventana,"A")
       ;For $ohref In $ohrefs
          ;If $ohref.href = "javascript:preLogout();" Then _IEAction($ohref,"click")
       ;Next
       _IELoadWait($ventana)
       ;Here come the problems with controls :/

       WinWait("Windows Internet Explorer","Do you want to")
       ControlClick("Windows Internet Explorer", "Aceptar", "[CLASSNN:Button1]")
        ;ControlSend("Windows Internet Explorer","Aceptar",1,"{ENTER}")
       WinWait("Windows Internet Explorer","For security reasons, please close your browser window")

       ;ControlSend("Windows Internet Explorer","Aceptar",2,"{ENTER}")
        ControlClick("Windows Internet Explorer","Aceptar",2)
       WinWait("Windows Internet Explorer","La página web que está viendo está intentando cerrar la ventana.¿Desea cerrarla?")
        ControlClick("Windows Internet Explorer","&Sí",6)
        ;IP check
        $IP = _GetIP ( )
        While @error = 1
            $IP = _GetIP ( )
        WEnd
        MsgBox(0,"Nueva IP publica","La nueva IP pública es: "& $IP)
        Exit

Now, there are 2 things that grabbed my attention and one that prevents me to finish the code:

1)In the part in which I do _IENavigate($ventana,"javascript:preLogout();") I also tried this other way:

_IELoadWait($ventana)
       $otables = _IETableGetCollection($ventana)
       For $otable In $otables
          If $otable.class = "menu1" Then
             $ohrefs = _IETagNameGetCollection($otable,"A")
             For $ohref In $ohrefs
                If $ohref.href = "javascript:preLogout();" Then _IEAction($ohref,"click")
             Next
          EndIf
       Next

And I got this error: ==> The requested action with this object has failed.:

If $otable.class = "menu1" Then

If $otable.class ^ ERROR

Maybe I'm using the tables in a bad way?

2)Another thing I tried was this code:

$ohrefs = _IETagNameGetCollection($ventana,"A")
       For $ohref In $ohrefs
          If $ohref.href = "javascript:preLogout();" Then _IEAction($ohref,"click")
       Next

And I received this error at the end of the execution of the script:

==> The requested action with this object has failed.:

If $ohref.href = "javascript:preLogout();" Then _IEAction($ohref,"click")

If $ohref.href ^ ERROR

However, it did what it was supposed to do, that is to log out :blink:

3)As I commented in the code, I can't click the windows that appear after logging out, I tried using winactive,controlfocus due to the help file saying that there are controls that resist to be clicked. I even tried using send("{ENTER}") as I did in a less sophisticated version of this script -because when I couldn't use the DOM I had to select each element using TAB but now I prefer to use controlsend and controlclick that allow to do other things at the same time- but it didn't function...

I would appreciate any help to continue ;)

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...