Skip to content
This repository was archived by the owner on Nov 21, 2019. It is now read-only.

Commit c15936f

Browse files
author
icymind
committed
fix bug: can not reset default gateway
1 parent f09b2cd commit c15936f

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ VRouter 在后台运行一个 openwrt 的虚拟机, 通过更改系统的默认
3434

3535
### 恢复网关
3636

37-
如果出 bug 造成无法上网或者无法解析域名, 而 VRouter 有无法恢复系统默认网关.可以手动恢复:
37+
如果出 bug 造成无法上网或者无法解析域名, 而 VRouter 又无法恢复系统默认网关.可以手动恢复:
3838

3939
```bash
4040
# 查找你的路由器地址, 假设命令输出1.2.3.4

js/vrouter-local.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,18 @@ class VRouter {
176176
if (dst === 'vrouter') {
177177
ip = this.config.vrouter.ip
178178
} else {
179-
const subCmd = `/usr/sbin/networksetup -getinfo ${networkService} | grep Router | awk -F ": " '{print $2}'`
180-
ip = await this.localExec(subCmd).then(ip => ip.trim())
179+
// const subCmd = `/usr/sbin/networksetup -getinfo ${networkService} | grep Router | awk -F ": " '{print $2}'`
180+
const subCmd = `/usr/sbin/networksetup -getinfo ${networkService} | grep Router`
181+
ip = await this.localExec(subCmd)
182+
.then((output) => {
183+
const ipReg = /(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/ig
184+
const match = ipReg.exec(output)
185+
if (match && match[1]) {
186+
return Promise.resolve(match[1])
187+
} else {
188+
return Promise.reject(Error('can not get Router IP'))
189+
}
190+
})
181191
}
182192
// const cmd = `sudo /sbin/route change default "${ip}"` +
183193
// ' && ' + `sudo /usr/sbin/networksetup -setdnsservers ${networkService} "${ip}"`

0 commit comments

Comments
 (0)