安装 OpenWrt
- 打开 Terminal 或 Command Prompt。
- 执行命令:
sudo npm install openwrt - 进入安装页面,选择默认的版本(通常是 3.x.x)。
配置 OpenWrt
- 执行命令:
sudo openwrt config normalize --skip --show-all --exclude-all -n <config-file>- 这里
<config-file>是你希望配置的 OpenWrt 文件名(config-singletons.json)。
- 这里
- 点击返回后,输入你的配置文件名,然后等待系统生成配置。
进入 OpenWrt
- 执行命令:
sudo openwrt enter --port <port_number> --port-range <port_range> --no-namespace<port_number>是你希望运行的 port 的编号。<port_range>是你希望运行的 port 的范围(168.1.1/255)。
- 点击返回后,选择要连接的服务器,然后等待系统连接。
开始使用 OpenWrt
- 执行命令:
sudo openwrt start --port <port_number> --port-range <port_range> --no-namespace这会启动 OpenWrt 服务,并在指定的 port 上运行你的脚本或配置。
- 你可以通过终端来查看服务的状态,执行命令
sudo openwrt status来查看。
编写脚本
- 执行命令:
sudo openwrt start --script script.js这会启动你的脚本,脚本需要使用 Node.js 的语法编写。
- 你可以使用 Node.js 的 built-in 函数,或者定义自定义函数来扩展脚本的功能。
调试和调试
- 在终端中运行脚本,
sudo openwrt start --script example.js - 如果脚本有错误,请查看配置文件或运行更简单的脚本来测试。
退出 OpenWrt
- 执行命令:
sudo openwrt exit
额外提示:
- 如果你有 Node.js,你也可以尝试运行脚本而不使用 OpenWrt。
- 定义好配置文件后,可以使用
openwrt start --script来启动脚本,或者运行简单的命令脚本。
OpenWrt 是一个简单的 Node.js 开发工具,适合快速创建脚本和配置,安装和配置很简单,但需要确保配置文件是安全的。


