Skip to content

Commit 1acd3ec

Browse files
committed
feat: 新增路由器返回公网ip指令
1 parent 4859fc5 commit 1acd3ec

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,6 @@
2929
开关端口转发:<code>op dkzf {on/off} {端口号}</code>
3030
<br>
3131
重启:<code>op reboot</code>
32+
<br>
33+
获取公网ip:<code>op ip</code>
3234
</details>

src/plugins/wechat-bot/wechat/task/openwrt.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,34 @@ async function restartRouter() {
146146
}
147147
}
148148

149+
// 获取公网ip
150+
async function getPublicIp() {
151+
try {
152+
const { stdout, stderr } = await sshIns.execCommand('curl -s https://ip.3322.net/')
153+
if (stderr) {
154+
return Promise.reject(stderr)
155+
}
156+
await wechatBotIns.sendByTarget({
157+
targetKey: 'wxid',
158+
targetValue: wxData.wxid,
159+
content: stdout
160+
})
161+
} catch (e) {
162+
await wechatBotIns.sendByTarget({
163+
targetKey: 'wxid',
164+
targetValue: wxData.wxid,
165+
content: 'get public ip fail'
166+
})
167+
return Promise.reject(e)
168+
}
169+
}
170+
149171
// 指令映射方法
150172
const fnMap = {
151173
dkzf: portForwardSwitch,
152174
dkzfls: portForwardList,
153-
reboot: restartRouter
175+
reboot: restartRouter,
176+
ip: getPublicIp
154177
}
155178

156179
async function handleOpenwrt(data) {

0 commit comments

Comments
 (0)