使用ESP8266连接到强制门户WiFi [英] Connect to captive portal wifi using ESP8266

查看:270
本文介绍了使用ESP8266连接到强制门户WiFi的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在受专属门户保护的wifi网络上连接基于ESP8266的传感器(我别无选择,我不能要求克减). 我有一个要登录的登录名/密码.

I would like to connect an ESP8266 based sensor on a wifi network protected by a captive portal (I've no other option, and I cannot ask for derogation). I have a login/password to connect.

从一台基本计算机上,当我连接到网络并发出Internet请求时(例如,我在Google上搜索"bl"),我得到了这样的页面:

From a basic computer, when I'm connected to the network and I do an Internet request (for example, I search "bl" on google), I got a page like this : https://url:1003/fgtauth?12291a0aff04200a

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <style type="text/css">
    ...
    </style>
    <body>
<div class="oc">
  <div class="ic">
    <form action="/" method="post">
      <input type="hidden" name="4Tredir" value= "https://www.google.com/search?q=test&ie=utf-8&oe=utf-8">
      <input type="hidden" name="magic" value="12291a0aff04200a">
      <input type="hidden" name="answer" value="0">
      <h1 class="logo">
        GENERAL CONDITIONS
      </h1>
      <p>
      I.    OBJET <br /> <br />
      Some blabla..
      </p>
      <h2>
        Do you agree to the above terms?
      </h2>
      <div class="fec">
        <input type="submit" value= "Yes, I agree" onclick="sb('1')">
        <input type="submit" value= "No, I decline" onclick="sb('0')">
      </div>
    </form>
   </div>
   </div>
   <script>
     function sb(val) {
       document.forms[0].answer.value = val;
       document.forms[0].submit();
      }
    </script>
  </body>
</html>

因此,我们在此页面中看到一个魔术值",它实际上是该会话的ID.当我单击同意"按钮时,会显示此页面 https://url:1003/:

So, we see in this page that we get a "magic value" that is in fact an id for the session. When I click the agree button, I get this page https://url:1003/ :

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <style type="text/css">
    ...
    </style>

    <title>
      Firewall Authentication
    </title>
  </head>
  <body>
    <div class="oc">
      <div class="ic">
        <form action="/" method="post">
        <input type="hidden" name="4Tredir" value= "https://www.google.com/search?q=bl&ie=utf-8&oe=utf-8">
        <input type="hidden" name="magic" value="122713150676bec1">
        <h1 class="logo">
          Authentication Required
        </h1>
      <h2>
        Please enter your username and password to continue.
      </h2>
        <div class="fer">
          <label for="ft_un">
            Username:
          </label>
            <input name="username" id="ft_un" style="width:245px">
            <br>
          </div>
          <div class="fer">
            <label for="ft_pd">
              Password:
            </label>
            <input name="password" id="ft_pd" type="password" style="width:245px">
          </div>
          <div class="fer">
            <input type="submit" value= "Continue">
          </div>
        </form>
      </div>
    </div>
  </body>
</html>

在这里,我填写了用户名和密码,它将把它们发送到服务器,然后单击确定返回空白页.

Here, I fill user and password and it will send them to the server that returns a blank page with OK.

因此,我想从ESP8266开始执行此步骤.我分两步看到了这一点:

So, I would like to do this step from an ESP8266. I see that in two steps :

  • 请求页面
  • 获取结果并存储魔术
  • 伪造同意"请求页面
  • 伪造用户/id/魔术"请求页面

ESP8266请求页面的示例可以在这里找到: https://github.com/iobridge/ThingSpeak-Arduino -Examples/blob/master/Ethernet/Arduino_to_ThingSpeak.ino 我们在这里看到,我们可以将POST请求发送为:

An example of requesting page for ESP8266 can be found here : https://github.com/iobridge/ThingSpeak-Arduino-Examples/blob/master/Ethernet/Arduino_to_ThingSpeak.ino We see here, that we can send POST request as :

client.print("POST /update HTTP/1.1\n");

这里有一个解析页面的好例子: http://blog.nyl .io/esp8266-led-arduino/

Here, there is a good example to parse a page : http://blog.nyl.io/esp8266-led-arduino/

因此,我可以这样做并发布答案,但是首先我需要一些有关如何创建上述假"请求的线索.

So, I might do it with that and post the answer, but first I need some clues about how to create the above "fake" requests.

有什么想法吗?

推荐答案

ESP8266不仅具有使用HTTPS的能力,实际上,最新的ESP8226 Arduino代码库还包含一个WiFiClientSecure类,用于连接HTTPS服务器.

The ESP8266 is more than capable of using HTTPS, in fact the latest ESP8226 Arduino codebase includes a WiFiClientSecure class for connecting to HTTPS servers.

假设此页面永远不会改变,并且您正在使用Arduino环境,则需要编写一些基本功能.其中之一将是您已经链接的初始GET函数,并检查您是否收到了所需的页面,或者是否已定向到门户.如果您被定向到门户,则需要编写一个等效的POST函数来发送我同意"响应.

Assuming this page will never change, and you're using the Arduino environment, you would need to write a few basic functions. One of these will be the initial GET function which you have already linked, and checks whether you received the page you wanted, or if you were directed to the portal. If you were directed to the portal, you would then need to write an equivalent POST function to send the "I Agree" response.

现在,此POST函数将要求您将HTTP表单编码的有效负载发送到包含"Answer"值的服务器-您可以在

Now, this POST function will require you to send an HTTP form encoded payload to the server containing the "Answer" value - You can read up on that here http://www.w3.org/TR/html401/interact/forms.html#h-17.13. Since you (probably) aren't expecting the page to change, you could hard code it to be something like this:

client.println("POST / HTTP/1.1");
// $PORTAL_HOST should be the host of the captive portal, e.g. 10.1.1.1
client.println("Host: $PORTAL_HOST");
client.println("Content-Type: application/x-www-form-urlencoded");
client.println("Content-Length: 8");
client.print("\n");
client.print("Answer=1");

发送该有效负载后,您应该会收到辅助用户/密码页面.从那里开始,很简单的事情是通过indexOf/substring或类似方法提取魔术/会话,然后使用现在提取的数据重复上述代码(如果需要).

Once you send that payload, you should receive your secondary user/password page. From there it's a simple matter of extracting the magic/session via indexOf / substring or something similar, and then repeating the above code with your now extracted data (if needed).

如果您需要更好地了解将要发送的内容,我建议您打开浏览器上的调试/网络"选项卡,并在浏览器定向到此门户页面时观看浏览器发送的确切数据.您将希望尽可能地模仿它.

If you need a better idea of what exactly you'll be sending, I'd advise you to open the debug/networking tab on your browser, and watch the exact data your browser sends when it's directed to this portal page. You will want to emulate this as closely as possible.

这篇关于使用ESP8266连接到强制门户WiFi的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆