代码之家  ›  专栏  ›  技术社区  ›  user1685565

wget发布表单以重新启动路由器

  •  2
  • user1685565  · 技术社区  · 10 年前

    我想重启我的Fritz!方框7390,使用wget。 Web界面有一个重启表单,如下所示:

    <form action="/system/reboot.lua" method="POST">
    <div id="btn_form_foot">
    <input type="hidden" name="sid" value="beb5683181c2ab9f">
    <button type="submit" name="reboot">Neu starten</button>
    </div>
    </form>
    

    我想提交这份表格。到目前为止,我尝试过这样做,但似乎不起作用:

    wget --post-data "sid=beb5683181c2ab9f" "http://fritz.box/system/reboot.lua"
    

    每次加载页面时,sid似乎都会更改。

    但我不确定这是否是问题所在,因为我可以通过添加来修复sid?sid=url示例

    2 回复  |  直到 7 年前
        1
  •  2
  •   pjvds    9 年前

    您不能仅通过POST发送到该url。首先需要获取有效的会话id。这可以通过对执行get请求来完成 http://fritz.box/checklogin.lua 然后从 LOCATION 标头值。然后,您可以使用此链接发布到 http://fritz.box/system/reboot.lua 包括会话id。

    以下是实现自动化的最低步骤:

    SID=$(curl -s -I "http://fritz.box/logincheck.lua" | grep -Fi Location | awk -F'[=]' '{print $2}')
    SID=$(curl -s -i -H "Content-Type: application/x-www-form-urlencoded" -H "Origin: http://fritz.box" -H "Referer: http://fritz.box/system/reboot.lua\?sid\=$SID" --data "reboot=&sid=$SID" -L http://fritz.box/system/reboot.lua | grep -Fi Location | awk -F'[=]' '{print $2}')
    curl -s http://fritz.box/reboot.lua?ajax=1&sid=$REBOOT_SID
    

    我创建了一个带有一些额外检查的小脚本,您可以在此处找到。您可以在以下位置找到完整的脚本,包括检查: http://git.io/v3zQs

        2
  •  0
  •   wivku    4 年前

    建议当前软件(v7.20+)的步骤是什么?
    最好是密码保护的路由器。

    我尝试使用Chrome开发工具信息更新它以使用最近的路径。
    它给出了一个状态码 200 和响应: {"reboot_state":"extern"} .
    但没有重启。

    Chrome开发者工具在按下 Restart UI中的按钮是:

    curl 'http://fritz.box/reboot.lua' \
      -H 'Connection: keep-alive' \
      -H 'Pragma: no-cache' \
      -H 'Cache-Control: no-cache' \
      -H 'User-Agent: Mozilla/5.0 (...) Chrome/86.0.4240.111 Safari/537.36' \
      -H 'DNT: 1' \
      -H 'Content-Type: application/x-www-form-urlencoded' \
      -H 'Accept: */*' \
      -H 'Origin: http://fritz.box' \
      -H 'Referer: http://fritz.box/' \
      -H 'Accept-Language: en,en-US;q=0.9,nl;q=0.8,de;q=0.7,la;q=0.6' \
      --data-raw 'ajax=1&sid=1fd4370b50b14b07&no_sidrenew=1&xhr=1&useajax=1' \
      --compressed \
      --insecure
    

    ( sid 每次登录后明显发生变化)