|
最早跟网上搜了一大堆,要么就是编译好的bin,要么就是无法用arduino编译的(懒得折腾esp开发环境)只会用arduino写代码
后来才搜到github的代码,发现作者的代码已经被收录到 esp8266 arduino 示例中,费眼的找了好久才发现
最早的中继名字叫,esp8266 wifi repeater,也就是早期满天飞的 bin 文件
现在这玩意叫 NAPT ,用8266连wifi,再发射一个新的AP,默认代码是在原来ssid名字后面加上extender发射
再说代码修改部分功能,我加上了AP默认SSID和密码,重要的是加了AP默认mac地址的修改,这功能太有用了。。。很多需要绑mac验证的功能。。。不说了
会用的自然知道用在哪里,不会用的就随便玩玩就好,不过看帖子有人说AP只能连4个client,这个我没试,另外8266天生低能。。。网速不要抱太大希望,毕竟重要的还是ssid和mac地址
有兴趣的可以看下这个8266管理界面,暂时没想好怎么把AP功能放进去,最近更新了LittleFS替换原来的SPIFFS,加了兼容ESP32,不过ESP32库缺少读取LittleFS信息的代码,就都留空了
另外,esp8266 broads 我升级到了最新的 2.0.3 老版本我不清楚是否有 include 的库,最好用最新的
https://github.com/happysoul/esp8266web
https://gitee.com/happysoul/esp8266web
基于这个例子修改的
本来想给代码加颜色的,发现代码中不支持,算了。。我都加上了 //----------------------------------- 来标注是我修改的部分
- // NAPT example released to public domain
- #if LWIP_FEATURES && !LWIP_IPV6
- #define HAVE_NETDUMP 0
- //要连接的wifi
- #ifndef STASSID
- #define STASSID "123456" //-----------------------------------
- #define STAPSK "password" //-----------------------------------
- #endif
- //AP配置信息
- #ifndef APSTASSID
- #define APSTASSID "AP_SSID" //-----------------------------------
- #define APPASSWORD "password" //-----------------------------------
- #endif
- //修改AP的MAC地址
- uint8_t newMACAddress[] = {0x00, 0xaa, 0xbb, 0xcc, 0xdd, 0xee};//-----------------------------------
- #include <ESP8266WiFi.h>
- #include <lwip/napt.h>
- #include <lwip/dns.h>
- #include <LwipDhcpServer.h>
- #define NAPT 1000
- #define NAPT_PORT 10
- #if HAVE_NETDUMP
- #include <NetDump.h>
- void dump(int netif_idx, const char* data, size_t len, int out, int success) {
- (void)success;
- Serial.print(out ? F("out ") : F(" in "));
- Serial.printf("%d ", netif_idx);
- // optional filter example: if (netDump_is_ARP(data))
- {
- netDump(Serial, data, len);
- //netDumpHex(Serial, data, len);
- }
- }
- #endif
- void setup() {
- Serial.begin(115200);
- Serial.printf("\n\nNAPT Range extender\n");
- Serial.printf("Heap on start: %d\n", ESP.getFreeHeap());
- #if HAVE_NETDUMP
- phy_capture = dump;
- #endif
- // first, connect to STA so we can get a proper local DNS server
- WiFi.mode(WIFI_STA);
- WiFi.begin(STASSID, STAPSK);
- while (WiFi.status() != WL_CONNECTED) {
- Serial.print('.');
- delay(500);
- }
- Serial.printf("\nSTA: %s (dns: %s / %s)\n",
- WiFi.localIP().toString().c_str(),
- WiFi.dnsIP(0).toString().c_str(),
- WiFi.dnsIP(1).toString().c_str());
- // give DNS servers to AP side
- dhcpSoftAP.dhcps_set_dns(0, WiFi.dnsIP(0));
- dhcpSoftAP.dhcps_set_dns(1, WiFi.dnsIP(1));
- WiFi.softAPConfig( // enable AP, with android-compatible google domain
- IPAddress(172, 217, 28, 254),
- IPAddress(172, 217, 28, 254),
- IPAddress(255, 255, 255, 0));
- // WiFi.softAP(STASSID "extender", STAPSK);
- Serial.print("mac:"); //-----------------------------------
- Serial.println(WiFi.macAddress()); //-----------------------------------
- WiFi.softAP(APSTASSID, APPASSWORD);
- //修改AP的MAC地址
-
- //wifi_set_macaddr(STATION_IF, &newMACAddress[0]);//ST模式 //-----------------------------------
- wifi_set_macaddr(SOFTAP_IF, &newMACAddress[0]);//AP模式 //-----------------------------------
-
- Serial.print("mac:"); //-----------------------------------
- Serial.println(WiFi.macAddress()); //-----------------------------------
- Serial.printf("AP: %s\n", WiFi.softAPIP().toString().c_str());
- Serial.printf("Heap before: %d\n", ESP.getFreeHeap());
- err_t ret = ip_napt_init(NAPT, NAPT_PORT);
- Serial.printf("ip_napt_init(%d,%d): ret=%d (OK=%d)\n", NAPT, NAPT_PORT, (int)ret, (int)ERR_OK);
- if (ret == ERR_OK) {
- ret = ip_napt_enable_no(SOFTAP_IF, 1);
- Serial.printf("ip_napt_enable_no(SOFTAP_IF): ret=%d (OK=%d)\n", (int)ret, (int)ERR_OK);
- if (ret == ERR_OK) {
- Serial.printf("WiFi Network '%s' with same password is now NATed behind '%s'\n", STASSID "extender", STASSID);
- }
- }
- Serial.printf("Heap after napt init: %d\n", ESP.getFreeHeap());
- if (ret != ERR_OK) {
- Serial.printf("NAPT initialization failed\n");
- }
- }
- #else
- void setup() {
- Serial.begin(115200);
- Serial.printf("\n\nNAPT not supported in this configuration\n");
- }
- #endif
- void loop() {
- }
复制代码
补充内容 (2023-2-10 10:13):
帖子无法改了
补充,这里只分享8266现有功能,请在法律法规允许范围内讨论和使用
就像菜刀正常使用合法,但威胁他人生命时就要接受法律制裁了...
补充内容 (2024-2-2 11:05):
完整版本 看20楼大佬的帖子,功能上就是 某些 app 的某些操作会判断 当前连接的 无线网ssid名字和mac地址,才能做某些操作。8266用来模拟 AP |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
x
打赏
-
查看全部打赏
|