0

I need help on writing a script to log my Netgear GS108Tv2 smart switch's web interface and to do some configurations on mac filtering on my school's window 7 pc. I tried to use the mechanize code and some examples i found on the net, but the web interface's code format seems a little different from the example in the mechanize folder i downloaded.

Below is the code i came up with after using the example. For now i would be very glad if i am able to just log in to the web interface as i believe that is pretty much all i can do. The rest might prove a little tough but i can work on them after i manage to log in.

I am very new to code writing and totally fresh to python. Hope i can get all the help i could. Thank you very much.

import mechanize

browser = mechanize.Browser()
browser.open("http://172.16.164.23/")
browser.select_form(nr = 0)
browser.form["pwd"] = "password"
browser.submit()

browser.open("http://172.16.164.23/base/web_main.html")

well that is pretty much all could come up with, there are no errors but it does not seem to work.

Below is the web interface's code.

<html><head>
    <link rel="stylesheet" href="/base/style.css" type="text/css">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <!-- Style Sheet link and Meta data     -->
    <title>NETGEAR GS108T</title> <!-- Netgear Page Title  -->

    <script src="/base/js/tabs_Layer2.js" type="text/javascript"></script>
    <script src="/base/js/rollover.js" type="text/javascript"></script>
    <script src="/base/js/browser.js" type="text/javascript"></script>
    <script language="javascript">
      var a1, a2, a3, a4, a5, a6, a7, a8;
      a1 = new Image(130,29);
      a1.src = "/base/images/tab_Login_off.gif";
      a2 = new Image(130,29);
      a2.src = "/base/images/tab_Login_on.gif";
      a3 = new Image(130,29);
      a3.src = "/base/images/tab_Login_ro.gif";
      a4 = new Image(130,29);
      a4.src = "/base/images/tab_Help_off.gif";
      a5 = new Image(130,29);
      a5.src = "/base/images/tab_Help_on.gif";
      a6 = new Image(130,29);
      a6.src = "/base/images/tab_Help_ro.gif";
      a7 = new Image(130,29);
      a7.src = "/base/images/onlinehelp_off.gif";
      a8 = new Image(130,29);
      a8.src = "/base/images/onlinehelp_on.gif";
    </script>
    <script type="text/javascript" language="JavaScript">
      //******************************************************************************
      //* Purpose: Display an input error message.
      //* Return:  none
      //******************************************************************************
      function DisplayErrorMsg()
      {
        alert(document.forms[0].err_msg.value);
      }

      function CheckError()
      {
        if (document.forms[0].err_flag.value == 1) 
        {
          DisplayErrorMsg();
        }
        document.forms[0].pwd.focus();
      }
    </script>

    <script language="javascript">
      <!--
      if (top != self)
      {
        top.location.href = "/base/web_main.html";
      }

      if (self.opener != undefined)
      {
        self.close();
        self.opener.location.reload();
      }  
      -->
    </script>
  </head>
  <body onload="CheckError()">
    <form method="POST" action="/base/main_login.html">
      <table class="tableStyle" height="100%">
        <tbody><tr class="topAlign">
          <td class="leftEdge">&nbsp;</td>
            <td valign="top">
              <table class="tableStyle">
                <tbody><tr>
                  <td class="leftInside"><img src="/base/images/clear.gif" width="8"></td>
                  <td colspan="2">
                    <table class="tableStyle">
                      <tbody><tr>
                        <td class="logoNetGear space50Percent topAlign"><a href="http://www.netgear.com/" target="_blank"><img src="/base/images/clear.gif" width="149" height="62"></a></td>
                        <td class="gs108tImage spacer50Percent topAlign rightHAlign"><a href="http://kbserver.netgear.com/products/GS108Tv2.asp" target="_blank"><img src="/base/images/clear.gif" width="190" height="60"></a></td> <!-- Used to get the top right logo image with help URL  -->
                      </tr>
                      <tr>
                        <td colspan="2" class="bottomAlign">
                          <table class="tableStyle">
                            <tbody><tr>
                              <td class="spacer20Percent bottomAlign"><table border="0" cellpadding="0" cellspacing="0">
                                <tbody><tr id="tabss" class="spacer100Percent">
                                  <td class="navTopCell"><a href="javascript:void(0)" onmouseover="OverTab(this,1);" onmouseout="OutTab(this,1);"><img src="/base/images/tab_Login_on.gif" border="0"></a></td>
                                  <td class="navTopCell"><a href="/base/help.html" onmouseover="OverTab(this,1);" onmouseout="OutTab(this,1);"><img src="/base/images/tab_Help_off.gif" border="0"></a></td>
                                </tr>
                              </tbody></table>
                            </td>
                            <td class="loginActionCell spacer80Percent rightHAlign padding5LeftRight"></td>
                          </tr>
                        </tbody></table>
                      </td>
                    </tr>
                  </tbody></table>
                </td>
                <td class="rightHAlign"><img src="/base/images/clear.gif" width="2"></td>
              </tr>
              <tr class="background-blue">
                <td><img src="/base/images/clear.gif" width="8"></td>
                <td colspan="2" class="padding7Top spacer100Percent">
                  <div id="primaryNav">
                    <table border="0" cellpadding="0" cellspacing="0">
                      <tbody><tr>
                        <td id="cloneTd" class="navCell">&nbsp;</td>
                      </tr>
                      <tr id="subTubs"></tr>
                    </tbody></table>
                  </div>
                </td>
                <td></td>
              </tr>
            </tbody></table>
          </td>
          <td class="rightEdge">&nbsp;</td>
        </tr>
        <tr class="topAlign">
          <td valign="top" class="leftBodyNotch topAlign">&nbsp;</td>
          <td>
            <table class="tableStyle">
              <tbody><tr class="topAlign">
                <td class="leftNextBodyNotch"><img src="/base/images/clear.gif" width="11" height="16"></td>
                <td class="middleBodyNotch spacer100Percent">&nbsp;</td>
                <td class="rightNextBodyNotch"><img src="/base/images/clear.gif" width="11"></td>
              </tr>
            </tbody></table>
          </td>
          <td class="rightBodyNotch">&nbsp;</td>
        </tr>
        <tr height="100%">
          <td rowspan="2" class="leftEdge">&nbsp;</td>
          <td valign="top">
            <table class="tableStyle" height="100%">
              <tbody><tr>
                <td class="leftInside"><img src="/base/images/clear.gif" width="8"></td>
                <td class="spacer100Percent loginTable topAlign">
                  <table class="loginBox">
                    <tbody><tr>
                      <td colspan="3">
                        <table class="tableStyle">
                          <tbody><tr>
                            <td colspan="2" class="subSectionTabTopLeft spacer80Percent font12BoldBlue">Login</td>
                            <td class="subSectionTabTopRight spacer20Percent"><a href="javascript: void(0);" onclick="newWindow('/base/help/help.html#userlogin','userlogin','448','336','resizable=yes')"><img src="/base/images/help_icon.gif" width="12" height="12" title="Click for help"></a></td></tr><tr><td colspan="3" class="subSectionTabTopShadow">&nbsp;</td>
                          </tr>
                        </tbody></table>
                      </td>
                    </tr>
                    <tr>
                      <td class="subSectionBodyDot">&nbsp;</td>
                      <td class="paddingsubSectionBodyNone">
                        <table class="tableStyle">
                          <tbody><tr>
                            <td class="font10Bold padding4Top">Password</td>
                            <td class="padding4Top"><input class="input" type="PASSWORD" name="pwd" maxlength="20" value=""></td>
                          </tr>
                          <tr>
                            <td colspan="2" class="padding5TopBottom10Right"><input type="IMAGE" name="login" src="/base/images/login_on.gif"></td>
                          </tr>
                        </tbody></table>
                      </td>
                      <td class="subSectionBodyDotRight">&nbsp;</td>
                    </tr>
                    <tr>
                      <td colspan="3" class="subSectionBottom">&nbsp;</td>
                    </tr>
                  </tbody></table>
                </td>
              </tr>
            </tbody></table>
          </td>
          <td rowspan="2" class="rightEdge">&nbsp;</td>
        </tr>
        <tr>
          <td>
            <table class="tableStyle">
              <tbody><tr>
                <td colspan="3" class="topBottomDivider" id="cloneTd"><img src="/base/images/clear.gif" height="3"></td>
              </tr>
              <tr>
                <td colspan="3" class="footerBody">
                  <table class="tableStyle rightHAlign" align="right">
                    <tbody><tr>
                      <td id="ButtonsDiv"></td>
                    </tr>
                  </tbody></table>
                </td>
              </tr>
            </tbody></table>
          </td>
        </tr>
        <tr>
          <td class="leftEdgeFooter"><img src="/base/images/clear.gif" width="11" height="9"></td>
          <td>
            <table class="tableStyle">
              <tbody><tr>
                <td class="leftBottomDivider"><img src="/base/images/clear.gif" width="11" height="9"></td>
                <td class="middleBottomDivider spacer100Percent"><img src="/base/images/clear.gif" height="9"></td>
                <td class="rightBottomDivider spacer1Percent"><img src="/base/images/clear.gif" height="9"></td>
              </tr>
            </tbody></table>
          </td>
          <td class="rightEdgeFooter"><img src="/base/images/clear.gif" width="11" height="9"></td>
        </tr>
        <tr>
          <td class="leftCopyrightFooter"><img src="/base/images/clear.gif" width="11" height="9"></td>
          <td class="middleCopyrightDivider">
            <table class="blue10 tableStyle">
              <tbody><tr class="topAlign">
                <td>Copyright © 1996-2013 NETGEAR ®</td>
              </tr>
            </tbody></table>
          </td>
          <td class="rightCopyrightFooter"><img src="/base/images/clear.gif" width="11" height="9"></td>
        </tr>
      </tbody></table>
      <input type="hidden" name="err_flag" size="16" maxlength="15" value="0">
      <input type="hidden" name="err_msg" size="128" maxlength="512" value="">
    </form>


</body></html>
icktoofay
  • 126,289
  • 21
  • 250
  • 231
Suou
  • 1
  • Similar log in issue. http://stackoverflow.com/questions/24880288/how-could-i-use-python-request-to-grab-a-linkedin-page?noredirect=1#comment38650186_24880288 – Stephen Lin Aug 04 '14 at 02:33
  • @m170897017 i tried it in hope that it will work, but it does not seem that case. I believe it is because the elements or what you call the codes on the netgear web interface, seems a little different. i am very thankful for your quick response to my question and it gave me hope to try and get this done as much as i can. – Suou Aug 04 '14 at 03:10
  • Yeah, I don't have your machine so I'm not able to debug it. Hope similar answer could help you. Update your question when you get new progress. – Stephen Lin Aug 04 '14 at 03:14

0 Answers0