openwrt之wifi 脚本指令与 uci 指令/ ap + sta / 配置连接上级路由器

root@xxx:~# wifi help
Usage: /sbin/wifi [down|detect|reload|status]

enables (default), disables or detects a wifi configuration

root@xxx:~# wifi up/down  //打开、关闭wifi 接口(包括ap、sta),但是不写会存储(重启设备,恢复默认值)

root@xxx:~# wifi detects > /etc/config/wireless   // 生成无线配置文件(uci get / set 获取/设置此配置文件内的值)

root@xxx:~# wifi status

{
"radio0": {
"up": false,
"pending": true,
"autostart": true,
"disabled": false,
"config": {
"channel": "auto",
"hwmode": "11ng",
"path": "platform\/qca953x_wmac",
"ht_capab": [
"LDPC",
"SHORT-GI-20",
"SHORT-GI-40",
"TX-STBC",
"RX-STBC1",
"DSSS_CCK-40"
],
"htmode": "HT20",
"country": "CN",
"txpower": 15,
"disabled": false
},
"interfaces": [
{
"section": "@wifi-iface[0]",
"config": {
"mode": "ap",
"ssid": "Leedarson_9A1462",
"encryption": "psk-mixed",
"ifname": "wlan0",
"key": "12345678",
"wps_pushbutton": true,
"network": [
"lan"
],
"mode": "ap"
}
},
{
"section": "@wifi-iface[1]",
"config": {
"encryption": "psk-mixed",
"ssid": "Leedarson",
"mode": "sta",
"bssid": "B8:55:10:17:55:68",
"ifname": "wlan0-1",
"key": "12345678",
"wps_pushbutton": true,
"mode": "sta",
"network": [
"wwan"
],
"disabled": false
}
}
]
}

}

root@xxxx:~# uci 
Usage: uci [<options>] <command> [<arguments>]
Commands:
batch
export     [<config>]
import     [<config>]
changes    [<config>]
commit     [<config>]
add        <config> <section-type>
add_list   <config>.<section>.<option>=<string>
del_list   <config>.<section>.<option>=<string>
show       [<config>[.<section>[.<option>]]]
get        <config>.<section>[.<option>]
set        <config>.<section>[.<option>]=<value>
delete     <config>[.<section>[[.<option>][=<id>]]]
rename     <config>.<section>[.<option>]=<name>
revert     <config>[.<section>[.<option>]]

reorder    <config>.<section>=<position>

root@xxxx:~# uci get wireless.@wifi-iface[1].ifname   //获取 wifi interface 1 的名称

wlan0-1

root@Leedarson:~# uci set wireless.@wifi-iface[1].disabled=0    //设置 打开wifi interface 1

每次设置参数后都需要提交回写uci commit 更改/etc/config/wireless配置文件内容,然后执行/etc/init.d/network restart 后方能生效。

总结 : 

    wifi up 会启动wifi内的所有接口(ap、sta),  uci set wireless.@wifi-iface[1].disabled=0 能打开某个接口,ap 或者sta ,需要执行uci commit 回写,而后执行wifi up生效,并不会重启网卡!

    连接上级路由器配置:  

        root@xx:~# uci set wireless.@wifi-iface[1].ssid=TP-LINK_EE520F                 //wifi 名称
        root@xx:~# uci set wireless.@wifi-iface[1].bssid=8A:25:93:F2:52:0F             //wifi mac 地址
        root@xx:~# uci set wireless.@wifi-iface[1].key=abcd@1234                         //wifi 密码

        root@xx:~# uci commit                                                                                  

        root@xx:~# wifi up        



  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值