首先 我们要知道这个是怎么设置的。
image
搜到了视频教程
image-1715133873820
image-1715134347678
知道考勤设置的是SSID以及MAC地址所以需要知道公司Wi-Fi路由器背面的MAC地址是多少,你们可以半夜偷偷去撬开老板存放路由器的保险柜,我就不用了。

知道他们怎么设置这个考勤的,那么做一个一模一样的Wi-Fi应该可以实现上下床打卡了。

首先我们找一个可以开启AP(Access Points)的东西,越小越好,像这样。
image-1715134473727

还要可以实时配置,防止老板突然换路由器,这里写一个简单网站前端。

root.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>wifi克隆</title>
    <style>
        body {
            display: flex;
            align-items: center;
            justify-content: center;
            height: 100vh;
        }

        .form {
            display: flex;
            flex-direction: column;
            align-items: center;
            width: 80%;
            max-width: 400px;
        }

        label {
            font-size: 16px;
            font-weight: bold;
            text-align: center;
            margin-bottom: 10px;
            width: 100%;
        }

        input {
            width: 100%;
            padding: 5px;
            margin-bottom: 10px;
        }

        button {
            width: 100%;
            padding: 10px;
            background-color: #007bff;
            color: #fff;
            border: none;
            cursor: pointer;
        }

        #result {
            margin-top: 10px;
            text-align: center;
        }
    </style>
    <script>
        window.onload = function () {
            find();
        }

        function find() {
            fetch("/find", {
                method: "POST",
                headers: {
                    "Content-Type": "application/x-www-form-urlencoded"
                }
            })
                .then(response => response.json())
                .then(data => {
                    if (data !== '') {
                        document.getElementById("ssid").value = data.ssid;
                        document.getElementById("password").value = data.password;
                        document.getElementById("macAddr").value = data.macAddr;
                    }
                })
                .catch(error => {
                    console.error("请求失败:" + error);
                });
        }

        function send() {
            var ssid = document.getElementById("ssid").value;
            var password = document.getElementById("password").value;
            var macAddr = document.getElementById("macAddr").value;
            if (ssid === "" || password === "" || macAddr === "") {
                alert("请输入完整信息");
                return;
            }

            fetch("/post", {
                method: "POST",
                headers: {
                    "Content-Type": "application/x-www-form-urlencoded"
                },
                body: "ssid=" + ssid + "&password=" + password + "&macAddr=" + macAddr
            })
                .then(response => response.json())
                .then(data => {
                    document.getElementById("result").innerHTML = data.result;
                })
                .catch(error => {
                    console.error("请求失败:" + error);
                });
        }
    </script>
</head>
<body>
<div>
    <div class="form">
        <label>WiFi名称<input id="ssid"/></label>
        <label>WiFi密码<input id="password"/></label>
        <label>MacAddr<input type="text" id="macAddr"/></label>
        <button onclick="send()">确定</button>
    </div>
    <div id="result"></div>
</div>
</body>
</html>

板子刷个MicroPython环境,可以很简单的写个后端,当然需要先默认开启Wi-Fi连上去你才打得开这个网站。

boot.py

import time

import network
import ujson


def check_file(filename):
    try:
        with open(filename, "r") as f:
            return True
    except Exception as e:
        return False

def wifi_ap(tssid, tpassword, tmac):
    ap = network.WLAN(network.AP_IF)
    ap.active(True)
    ap.config(mac=bytearray(bytes.fromhex(tmac.replace(':', ''))))
    ap.config(ssid=tssid, password=tpassword)
    ap.config(authmode=4)

def wifi_def_ap():
    ap = network.WLAN(network.AP_IF)
    ap.config(ssid='您配吗')
    ap.active(True)


try:
    if check_file("wifi_config_mac.json"):
        with open('wifi_config_mac.json', 'r+') as f:  # 尝试打开wifi_config文件
            config = ujson.loads(f.read())  # 获取wifi_config的信息
        wifi_ap(config['ssid'], config['password'], config['macAddr'])  # 进行WiFi连接
    else:
        wifi_def_ap()
except Exception as e:
    print("Error:", e)
    wifi_def_ap()


后端这里有个简单的库,安装非常简单
https://microdot.readthedocs.io/en/latest/intro.html#micropython-installation

main.py

import time
import network
import ujson

from microdot import Microdot, send_file

app = Microdot()

sta_if = network.WLAN(network.STA_IF)


def parse_string_params(input_string):
    param_list = input_string.split('&')
    params = {}
    for param in param_list:
        key, value = param.split('=')
        params[key] = value

    return params


def connect_wifi(wifi_ssid, wifi_password):
    # 连接 WiFi
    sta_if.active(True)
    sta_if.connect(wifi_ssid, wifi_password)
    # 等待连接成功
    count = 0
    while not sta_if.isconnected():
        count += 1
        print('第' + str(count) + 'ci')
        time.sleep(1)
        if count > 10:  # 如果检测到大于10次连不上(10秒后还没有联网)关闭WiFi并返回
            sta_if.active(False)
            return False
    if sta_if.isconnected():
        print('network config:', sta_if.ifconfig())
        print('')
        return True
    else:
        print('failed to connect to network')
        return False


def check_file(filename):
    try:
        with open(filename, "r") as f:
            return True
    except Exception as e:
        return False


@app.get('/')
def hello(request):
    return send_file('root.html')


@app.post('/find')
def find(request):
    if check_file("wifi_config_mac.json"):
        with open('wifi_config_mac.json', 'r+') as f:
            config = ujson.loads(f.read())
            return config
    return {"ssid": "demo", "password": "12", "macAddr": "2333"}


@app.post('/post')
def post(request):
    body = request.body
    params = parse_string_params(body.decode('utf-8'))
    config = dict(ssid=params["ssid"], password=params["password"], macAddr=params['macAddr'])
    with open('wifi_config_mac.json', 'w+') as f:
        f.write(ujson.dumps(config))
    return {"result": "配上了!"}
    #if connect_wifi(params["ssid"], params["password"]):
    #     config = dict(ssid=params["ssid"], password=params["password"], macAddr=params['macAddr'])
    #     with open('wifi_config_mac.json', 'w+') as f:
    #         f.write(ujson.dumps(config))
    #     return {"result": "配上了!"}
    # else:
    #     return {"result": "你不配!账号密码都搞错了"}

app.run(port=80)

文件结构

最后文件结果大概是这样
image-1715135612002

重启以后会出现一个WI-FI你连接它
image-1715135690218

连上以后打开192.168.4.1就可以看到这个网站了

image-1715135733103

改一改就可以克隆你们想要的Wi-Fi
image-1715135777764
image-1715135782291
image-1715135793405
image-1715135798584

验证下你自己填写的地址

image-1715135822099

Q.E.D.


味无味处求吾乐,材不材间过此生。