沙唐桔

梅林定时开关访客网络

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

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

实现方法

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

准备工作:启用 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(这条重启了之后,访客限速脚本失效,要重新运行

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