梅林定时开关访客网络

一直搞不懂,据说很强大的梅林,居然连定时开关访客网络这样一个功能都没有现成的(主 WIFI 网络是可以设置定时开关的)。还有就是竟然不能只对访客网络限速!!!——也许资本主义国家可能没有这样的需求吧。

兲朝的 TP-LINK 路由器有些是带定时开关访客网络这个功能的,官网可是设置方法都有呢——访客网络如何定时开启或关闭?▼显示

 523-TP-LINK-GuestWifi

实现方法

定时执行脚本开启访客网络,定时执行脚本关闭访客网络。

准备工作:启用 jffs——系统管理 -> 系统设置 -> Persistent JFFS2 partition -> Enable JFFS custom scripts and configs。接着打开 SSH,方便通过 WinSCP 传输文件到路由器。

建立一个空白文件,我这里用了 .sh 后缀,取名 GuestWIFIOn.sh,其实没有后缀也可以,编码 utf-8。写入下面的代码并保存。

#!/bin/sh
nvram set wl0.1_bss_enabled=1
nvram set wl0.1_radio=1
nvram commit
service restart_wireless

再建立一个文件:GuestWIFIOff.sh,代码:

#!/bin/sh
nvram set wl0.1_bss_enabled=0
nvram set wl0.1_radio=0
nvram commit
service restart_wireless

两个文件通过 WinSCP 传输到路由器的 /jffs/scripts 目录下,记得权限改为 0755。接着在 wan-start 文件里添加下面的代码:

cru a Start-Guest-WIFI "00 08 * * * /jffs/scripts/GuestWIFIOn.sh"
cru a Stop-Guest-WIFI "00 22 * * * /jffs/scripts/GuestWIFIOff.sh"

意思是每天早上八点开启访客网络,每天晚上十点关闭访客网络。代码添加完,重启一下路由器就生效。

这个方法有个缺点:执行开启和关闭访客网络脚本的时候,主 WIFI 信号也会断一下(目测中断时间在半分钟以内)

RT-AC68U + KoolShare 改版梅林 380.66_4-X7.5 测试通过。

折腾完忽然觉得其实没什么太大用处。囧。

参考文章

0、Setting a random password for guest wifi▼显示

#61

I found an easier way (for me) to manage my kid's WiFi access. I enable/disable guest networks via a small script that my wife and I can run from a term app on our phones. The networks then automatically turn off via a cron set to run in the evening. This way, they don't have to "forget the network" and retype a password every day. Also, if I want to turn off their WiFi at some point during the day, I just run the script with "off" as an argument instead of "on".

Code:
#/bin/sh

# Turn on/off kid's wifi for 16 hours

if [ $1 = "on" ]; then
nvram set wl0.1_bss_enabled=1
nvram set wl0.1_expire_tmp=57600
service restart_wireless
elif [ $1 = "off" ]; then
nvram set wl0.1_bss_enabled=0
nvram set wl0.1_expire_tmp=0
service restart_wireless
else
echo "Invalid parameter! Acceptable parameters are ON or OFF"
fi

1、Script to switch on or off a VLAN (guest wireless)▼显示

It seems that:
wl -i wl0.1 radio off
turns the virtual wireless interface off but it has a "small" side effect: it also turns the real interface wl0 off at the same time! So if you try to manipulate the virtual interface wl0.1 with wl remember that it's always bound to the actual interface. So this is not a solution.
However I guess if you have another wireless interface wl1 (e.g. 5 Ghz) you could use wl to change wl0.1 without side effects to wl1. But I don't have such a router now at hand so I can't test this. And it would still mess up wl0.

I now also see why wl0.1_bss_enabled is used in the original script. It's just trying to simulate the behaviour of the Tomato GUI. I checked what changes in the nvram when you enable and disable guest wifi from the GUI. And the result is that wl0.1_bss_enabled and wl0.1_radio go hand in hand.

So the only issue I have with the original script is the echo which is like shouting at the sky :)
So here's an improved version of the script (which also fixes the incorrect usage of the term VLAN):
Code:
if [ $(nvram get wl0.1_radio) -eq 0 ]; then
nvram set wl0.1_bss_enabled=1
nvram set wl0.1_radio=1
nvram commit
service wireless restart
logger -t "custom script" -p info "Button pressed: guest wifi turned ON"
else
nvram set wl0.1_bss_enabled=0
nvram set wl0.1_radio=0
nvram commit
service wireless restart
logger -t "custom script" -p info "Button pressed: guest wifi turned OFF"
fi
Last edited: Jan 31, 2016

2、Time-of-Day limits on Guest access▼显示

Create two scripts:
guest_wifi_start.sh

#!/bin/sh

####################################################################################
#                                                                                  #
# Start / Stop Guest WIFI                                                          #
# L. de Bles, 2014                                                                 #
#                                                                                  #
# Called via init-start                                                            #
#                                                                                  #
# 2.4 Ghz Radio                                                                    #
# wl0.1 ---> Guest Network 1                                                    #
# wl0.2 ---> Guest Network 2                                                    #
# wl0.3 ---> Guest Network 3                                                    #
#                                                                                  #
# 5 Ghz Radio                                                                      #
# wl1.1 ---> Guest Network 1                                                    #
# wl1.2 ---> Guest Network 2                                                    #
# wl1.3 ---> Guest Network 3                                                    #
#                                                                                  #
####################################################################################

# start: enabled=1
# stop: enabled=0

   nvram set wl0.1_bss_enabled=0
   service restart_wireless

and

guest_wifi_stop.sh
Code:
#!/bin/sh

####################################################################################
# #
# Start / Stop Guest WIFI #
# L. de Bles, 2014 #
# #
# Called via init-start #
# #
# 2.4 Ghz Radio #
# wl0.1 ---> Guest Network 1 #
# wl0.2 ---> Guest Network 2 #
# wl0.3 ---> Guest Network 3 #
# #
# 5 Ghz Radio #
# wl1.1 ---> Guest Network 1 #
# wl1.2 ---> Guest Network 2 #
# wl1.3 ---> Guest Network 3 #
# #
####################################################################################

# start: enabled=1
# stop: enabled=0

nvram set wl0.1_bss_enabled=0
service restart_wireless
Example is for wl0.1 (Guest Network 1 2,4Ghz)

Create cronjobs with help of init-start script

init-start

Code:
#!/bin/sh

# L. de Bles, 2014
#
# * * * * * command to execute
# - - - - -
# | | | | |
# | | | | |
# | | | | +----- day of week (0 - 7) (0 to 6 are Sunday to Saturday, or use names; 7 is Sunday,
# | | | +------- month (1 - 12)
# | | +--------- day of month (1 - 31)
# | +----------- hour (0 - 23)
# +------------- min (0 - 59)
#
# --------------------------------------------------------------------------------------------------

cru a Start-Guest-WIFI "00 09 * * * /jffs/scripts/guest_wifi_start.sh"
cru a Stop-Guest-WIFI "00 17 * * * /jffs/scripts/guest_wifi_stop.sh"
Place all (three) scripts in /jffs/scripts.
Don't forget to chmod a+rx /jffs/scripts/*

After rebooting the router guest wifi starts and stops.
Last edited: Aug 25, 2014
__________________
RT-AC88U Merlin 380.64 (Main router)
RT-AC68U Merlin 380.64 (AP mode)

**One SSID **Different Channels **Total coverage at 2,4 and 5 GHz

3、用命令开关访客网络▼显示

3#+5# 自己找到了,如下:
nvram set wl0.1_bss_enabled=1
nvram set wl0.1_expire_tmp=10800
nvram commit
service restart_wireless

4、有没有不重启开关访客无线的命令?▼显示

现在论坛里能找到的命令是:
1.不用重启开关所有无线,包括主无线跟访客无线
2.4G
wl -i eth1 radio off
wl -i eth1 radio on

wl -i eth1 up
wl -i eth1 down

5G
wl -i eth2 radio off
wl -i eth2 radio on

wl -i eth2 up
wl -i eth2 down

2.需要重启才有效的单独开关访客无线
2.4G nvram set wl0.1_bss_enabled=0关
nvram set wl0.1_bss_enabled=1开

nvram commit
5G nvram set wl1.1_bss_enabled=0关
nvram set wl1.1_bss_enabled=1开

nvram commit
3.不用重启断开访客无线,但是人家还能搜的到的,能连的上就是上不了网
关闭2.4访客: ifconfig wl0.1 down或者
ip link set wl0.1 down
启动2.4访客: ifconfig wl0.1 up或者
ip link set wl0.1 up(这条重启了之后,访客限速脚本失效,要重新运行
关闭5G访客 ifconfig wl1.1 down或者
ip link set wl1.1 down

开启5G访客 ifconfig wl1.1 up或者
ip link set wl1.1 up(这条重启了之后,访客限速脚本失效,要重新运行

++++++++++++++++++++++++++++++++++++++++++++++++
就是没找到不用重启开关访客网络的命令,向各位大神讨一个好用的,还请大家不要吝啬吆

支付宝扫码打赏微信打赏

如果文章对您有帮助,欢迎移至上方按钮打赏老杨

声明: 除非注明,常阳时光文章均为原创,转载请以链接形式标明本文地址
本文地址:https://cyhour.com/523/
Tags:  , 

Comments:12

  1. 感觉没什么必要,特别是在我家。。
    路由放的位置,正好出门只有-85dBm以下了,能上也卡卡的。

    2017.07.01 14:57 # 回复
    1楼
    • @kn007 其实我也只是以前有这个需求,因为邻居的蹭我的 WIFI 的,现在邻居们都用上了移动免费光宽带了。

      2017.07.01 17:37 # 回复
      • @老杨 哈哈哈,好吧。我能说我用着电信,偶尔页蹭下邻居的移动宽带么。。。毕竟20M国际出口的上传下载速度,确实比电信强多了

        2017.07.01 17:39 # 回复
        • @kn007 我现在自己也用着移动的免费宽带呢,不过明年应该就不免费了。移动的上传确实很爽。

          2017.07.01 17:58 # 回复
  2. 然并卵~
    现在流量便宜了~大巴流量用不完~

    2017.07.01 19:04 # 回复
    2楼
    • @chencool 流量?开玩笑,WIFI 有时候都不稳定,4G 信号就更扯淡了,再多的流量也是然并卵,还有电脑呢……

      2017.07.01 20:24 # 回复
  3. 梅林是什么?第一次看到

    2017.07.01 22:09 # 回复
    3楼
    • @安满 一个第三方修改的华硕路由器固件。官网好像是这个:https://asuswrt.lostrealm.ca/。

      2017.07.01 23:08 # 回复
  4. 折腾完发现没什么卵用,因为根本没有访客(好悲伤去哭一会儿

    2017.07.02 10:26 # 回复
    4楼
    • @axiu 访客肯定会有的,养兵千日用兵一时嘛。

      2017.07.02 10:51 # 回复
  5. 天朝的路由器都比较傻瓜啊

    2017.07.02 23:54 # 回复
    5楼

发表留言