使用ESP8266连接到强制门户WiFi

ier*_*ero 3 arduino wifi captivenetwork esp8266

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

从基本计算机上,当我连接到网络并发出Internet请求时(例如,我在Google上搜索“ bl”),我得到了这样的页面: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>
Run Code Online (Sandbox Code Playgroud)

因此,我们在此页面中看到一个“魔术值”,它实际上是该会话的ID。当我单击同意按钮时,我得到此页面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>
Run Code Online (Sandbox Code Playgroud)

在这里,我填写了用户名和密码,它将把它们发送到服务器,然后按OK返回空白页。

因此,我想从ESP8266开始执行此步骤。我分两步看到:

  • 请求页面
  • 得到结果并存储魔术
  • 伪造“同意”请求页面
  • 伪造“用户/标识/魔术”请求页面

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

client.print("POST /update HTTP/1.1\n");
Run Code Online (Sandbox Code Playgroud)

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

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

有任何想法吗 ?

Daw*_*ion 7

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

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

现在,此POST功能将要求您将包含“应答”值的HTTP表单编码有效负载发送到服务器-您可以在此处进行读取http://www.w3.org/TR/html401/interact/forms.html #h-17.13。由于您(可能)不希望页面发生更改,因此您可以将其硬编码为如下所示:

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");
Run Code Online (Sandbox Code Playgroud)

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

如果您需要对要发送的内容有更好的了解,建议您打开浏览器上的“调试/联网”选项卡,并在浏览器定向到此门户页面时查看其发送的确切数据。您将需要尽可能地模仿它。