软路由 其他 C# 工具 Docker JAVA X86 OpenWrt 飞牛OS iStoreOS 小米路由器 Xray Windows Hyper-V macvlan Windows Server Selenium Mono.Cecil Test Email Java 快捷键 IDEA ImmortalWrt Jenkins Gitlab Redis Mysql Win10 Debian CentOS Docker SpringBoot
头像
WGZZ
小米路由器API
2024-09-30 22:17 2024-09-30 22:17 2 0

小米路由器API

登录页:http://192.168.31.1/cgi-bin/luci/web

//获取key和deviceId
String key = "";
String deviceId = "";
Document document = HttpUtils.getDocument("http://192.168.31.1/cgi-bin/luci/web");
String html = document.toString().replace("\r", "").replace("\n", "").replace("\t", "");
Matcher keyMatcher = Pattern.compile(".*key: \'(.*?)\',").matcher(html);
if(keyMatcher.find()) {
    key =keyMatcher.group(1);
}
Matcher deviceIdMatcher = Pattern.compile("deviceId = \'(.*?)\';").matcher(html);
if(deviceIdMatcher.find()) {
    deviceId =deviceIdMatcher.group(1);
}

登录:http://192.168.31.1/cgi-bin/luci/api/xqsystem/login

//随机串
public static String getNonce(String deviceId){
    Integer type =0;
    long time = System.currentTimeMillis() / 1000;
    int random = new Random().nextInt(10000);
    return type+"_"+deviceId+"_"+time+"_"+random;
}
//密码加密
public static String getPassword(String pwd,String nonce){
    String key="a2ffa5c9be07488bbb04a3a47d3c5f6a";
    return  DigestUtil.sha256Hex(nonce+ DigestUtil.sha256Hex(pwd+key));
}
​
public void t1(){
    String nonce = getNonce("1c:83:41:ca:93:2a");
    String password = getPassword("l5w9m6abc",nonce);
​
    String url = String.format("http://192.168.31.1/cgi-bin/luci/api/xqsystem/login");
    Connection connect = Jsoup.connect(url);
    HashMap<String, String> headers = new HashMap<>();
    headers.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
    headers.put("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36 Edg/125.0.0.0");
    connect.headers(headers);
    Map<String, String> data = new HashMap<>();
    data.put("username", "admin");
    data.put("password", password);
    data.put("logtype", "2");
    data.put("nonce", nonce);
    connect.data(data);
    Document post = connect.post();
}
​
//响应
{"url":"/cgi-bin/luci/;stok=fde962455af256e973c565eb844ccd4b/web/home","token":"fde962455af256e973c565eb844ccd4b","code":0}

网络信息:http://192.168.31.1/cgi-bin/luci/;stok=/api/xqnetwork/wan_info

{
    "info": {
        "mac": "A4:A9:36:11:F5:C6",
        "mtu": "1480",
        "details": {
            "password": "a123456",
            "ifname": "eth3",
            "dns": [
                "180.76.76.76",
                "119.29.29.29"
            ],
            "mtu": "1480",
            "wanType": "pppoe",
            "special": "1",
            "username": "0000000000",
            "peerdns": "0"
        },
        "special": "1",
        "dnsAddrs1": "119.29.29.29",
        "gateWay": "129.210.62.1",
        "ipv6_info": {
            "ifname": "pppoe-wan",
            "dns": [
                "240e:50:c800::210",
                "240e:50:5000::80"
            ],
            "peerdns": "1",
            "wanType": "native",
            "ip6addr": [
                "240e:382:503:ea00:4c7a:273f:b2e2:621a/64"
            ],
            "status": true,
            "ip6gw": "fe80::ce1a:faff:fee7:f760",
            "lan_ip6prefix": [
                "240e:382:503:ea00::"
            ],
            "lan_ip6addr": [
                [
                    "240e:382:503:ea00::1/64"
                ]
            ]
        },
        "uptime": 9059,
        "dnsAddrs": "180.76.76.76",
        "status": 0,
        "ipv6_show": 1,
        "link": 1,
        "ipv4": [
            {
                "mask": "255.255.255.255",
                "ip": "129.210.62.28"
            }
        ]
    },
    "code": 0
}

端口转发

删除端口

http://192.168.31.1/cgi-bin/luci/;stok={token}/api/xqsystem/delete_redirect
//入参
{
    port: 1111, //端口
    proto: 1 , //协议 1-TCP 2-UDP 3-TCP/UDP
}
//响应
{"code":0}

新增端口

http://192.168.31.1/cgi-bin/luci/;stok={token}/api/xqsystem/add_redirect
//入参
{
    name: 测试
    proto: 3 //协议 1-TCP 2-UDP 3-TCP/UDP
    sport: 1111 //外部端口
    ip: 192.168.31.100
    dport: 1111 //内部端口
}
//响应
{"code":0}

新增范围端口

http://192.168.31.1/cgi-bin/luci/;stok={token}/api/xqsystem/add_range_redirect
//入参
{
    name: 测 
    proto: //协议 1-TCP 2-UDP 3-TCP/UDP
    fport: 10 //开始端口
    tport: 20 //结束端口
    ip: 192.168.31.102
}
//响应
{"code":0}
赞赏
作者:WGZZ
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0协议
转载请注明文章地址及作者
{{globalState.toComment.userName[0]}}
{{globalState.toComment.userName}}
{{globalState.toComment.commentContent}}
{{globalState.toComment.createTime.slice(0, 16)}} {{globalState.toComment.userIpAddr}} 取消回复
>
邮件通知
确认
评论
暂无评论,点击右上角 发布
{{comment.userName[0]}}
{{comment.userName}}
{{comment.commentContent}}
{{comment.createTime.slice(0, 16)}} {{comment.userIpAddr}} 回复
{{child.userName[0]}}
{{child.userName}} {{child.toUserName}}
{{child.commentContent}}
{{child.createTime.slice(0, 16)}} {{child.userIpAddr}} 回复
2022-2025 BY WG日记
本站已运行 {{globalState.formattedTime}}