写了个python服务器,其实主要是用来web配网的。
import socket
import sys
import re
SEND_BUF_SIZE = 256
RECV_BUF_SIZE = 256
def start_tcp_server(ip, port):
html_match = r'(.{0,30})(\w{4})\=(\w{0,16})\&(\w{8})\=(\w{0,30})' #r'(.{0,30})(\w{4})\=(\w{0,16})\&(\w{8})\=(\w{8,20})
response = '<!DOCTYPE html><html><head><meta charset="utf-8"><title>感谢使用</title></head><body><h1>已收到账号密码,正在自动连接网络,请稍等</h1></body></html>'
html='<!DOCTYPE html><html><head><!--<meta http-equiv="Content-Type"content="text/html; charset=utf8"/>--><meta http-equiv="Content-Type"content="text/html; charset=utf8"Cache-Control="no-cache"><meta name="viewport"content="width=device-width, initial-scale=1.0"><title>欢迎使用网页配网</title></head><body><form action="wifi"method="get"name=my>WiFi名称:<input type="text"name="ssid"placeholder="请输入您WiFi的名称"id="a"><br>WiFi密码:<input type="text"name="password"placeholder="请输入您WiFi的密码"id="b"><br><input type="submit"name="button"id="button"value="发送"><input type="button"value="跳过"οnclick="jump()"></form><script language="javascript">function jump(){var ssid=my.ssid.value;var password=b.value;var xmlhttp=new XMLHttpRequest();xmlhttp.open("GET","/jump?ssid="+ssid+"&password="+password,true);xmlhttp.send()}</script></body></html>'
#with open('html_.txt','r',encoding = 'utf-8') as f:
# html = f.read()
# create socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_address = (ip