Created
April 28, 2015 08:13
-
-
Save netwjx/26ac42cdf7a475402f26 to your computer and use it in GitHub Desktop.
路由更新
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
routes = | |
'192.168.0.0': '255.255.0.0' | |
Future = require 'fibers/future' | |
child_process = require 'child_process' | |
iconv = require 'iconv-lite' | |
Future.task -> | |
stdout = exec 'route print' | |
IF = IF_NAME = 0 | |
stdout.replace /^ (\d+).+\.([\w\(\)]+ Ethernet .+)$/m, (_, $1, $2)-> | |
IF = $1 | |
IF_NAME = $2 | |
stdout = exec 'ipconfig' | |
NW = 0 | |
if ~(n = stdout.indexOf 'qunarservers.com') and | |
~(n = stdout.indexOf '默认网关', n) and | |
~(n = stdout[n..].match /\d+\.\d+\.\d+\.\d+/) | |
NW = n[0] | |
console.log "网关:#{NW} 接口:#{IF} #{IF_NAME}" | |
stats = for own IP, MASK of routes | |
execFuture "route add #{IP} MASK #{MASK} #{NW} IF #{IF}", encoding: 'hex' | |
do s.wait for s in stats | |
console.log '完成' | |
.detach() | |
execFuture = Future.wrap child_process.exec, 'multi' | |
exec = (cmd)-> | |
[stdout] = execFuture cmd, encoding: 'hex' | |
.wait() | |
iconv.decode new Buffer(stdout, 'hex'), 'gbk' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment