4

使用脚本重启维珍路由器

 2 years ago
source link: https://jixun.uk/posts/2022/auto-reboot-vm-hub-3/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

那些随 ISP 套餐配套的路由器通常都有各种各样的问题,其中一个万能的解决方案就是每日凌晨定期重启路由器。

前置条件 #

  • 一个闲置的树莓派或同类型的单片机,或其它 24/7 开机的设备;
    • 该设备需要能够正常执行 Unix Shell 脚本,如 bash
  • 路由器为 Virgin Media Hub 3.0(别名 SuperHub 3)。其它路由器未测试。

脚本 #

一个简单的 bash 脚本,用来重启路由器非常方便:

#!/bin/sh

############################
# Virgin Media Router Setup

VM_HOST="192.168.0.1" # Modem mode => 192.168.100.1
VM_USER="admin"
VM_PASS="12345678" # Router password

############################

NOW=0
NONCE=12345

_login_arg="$(printf "%s:%s" "$VM_USER" "$VM_PASS" | base64)"
CRED="$(curl -s "http://${VM_HOST}/login?arg=${_login_arg}&_n=${NONCE}&_=${NOW}")"
curl -s "http://${VM_HOST}/snmpSet?oid=1.3.6.1.2.1.69.1.1.3.0=2;2;&_n=${NONCE}&_=${NOW}" \
  -H "Cookie: credential=$CRED"

将上述内容其保存至 /usr/local/bin/reboot_vm_router 并设定可执行权限(chmod a+x /usr/local/bin/reboot_vm_router)后即可。

每日自动执行 #

将下述内容写入到 /etc/cron.d/reboot_vm_router 即可。

# Reboot VM router at 4:30 AM each day
30 4 * * * root /usr/local/bin/reboot_vm_router

※ 若是 /etc/cron.d 目录不存在,可能你使用的 crontab 版本不支援从该目录加载配置文件。在这种情况下,将上述内容添加到 /etc/crontab 文件的结尾即可。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK