我想阻止下载值超过“20480”的mac地址:
json文件:
{
"client_length": 3,
"clients": {
"ac:07:5f:77:40:e9": {
"id": 1,
"ip": "192.168.5.40",
"mac": "ac:07:5f:85:40:e9",
"added": 1576258952,
"active": 1576264642,
"duration": 5711,
"token": "4d8fd3ce",
"state": "Authenticated",
"downloaded": 45059,
"avg_down_speed": 63.12,
"uploaded": 2976,
"avg_up_speed": 4.17
},
"ac:e0:10:55:2d:78": {
"id": 2,
"ip": "192.168.5.132",
"mac": "ac:e0:10:12:2d:75",
"added": 1576258985,
"active": 1576264663,
"duration": 5678,
"token": "35dfa494",
"state": "Authenticated",
"downloaded": 18663,
"avg_down_speed": 26.3,
"uploaded": 4986,
"avg_up_speed": 7.03
},
"58:48:44:db:ba:ba": {
"id": 3,
"ip": "192.168.5.93",
"mac": "58:48:22:db:ba:be",
"added": 1576258973,
"active": 1576264662,
"duration": 5690,
"token": "139fede2",
"state": "Authenticated",
"downloaded": 187876,
"avg_down_speed": 264.15,
"uploaded": 7910,
"avg_up_speed": 11.12
}
}
}
此外,这是结果,ndsctl json
而且总是会改变。ndsctl 是 nodogsplash 包的一部分。我已经在 OpenWrt (BusyBox v1.28.4) 上安装了这个包。
我的目标:
上面的 json 给了我一些信息。根据这个文件,我想阻止ac:07:5f:77:40:e9
,58:48:44:db:ba:ba
因为它们的下载值超过了“20480”。
我需要一个 bash 脚本来为我做这件事。
阻止mac地址的命令:
ndsctl block ac:07:5f:77:40:e9
ndsctl block 58:48:44:db:ba:ba
我做了一些事情:
root@OpenWrt:~# cat test.json | grep "mac\|downloaded"
"mac":"ac:07:5f:85:40:e9",
"downloaded":45059,
"mac":"ac:e0:10:55:2d:78",
"downloaded":18663,
"mac":"58:48:44:db:ba:ba",
"downloaded":187876,
任何想法?
对于大多数 Unices来说,有一个用于命令行的 JSON 解析器,称为
jq
随时可用(这可能必须从您的包系统中安装)。有了它,就可以轻松解析出下载次数超过20480次的条目的MAC地址。
获取这些信息后,您可以将它们一一传递给
ndsctl block
usingxargs
:这假定 JSON 文档保存在
file.json
.对于给定的 JSON 文档,这将运行两个命令