-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroute.js
38 lines (35 loc) · 1.01 KB
/
route.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import iproute from 'iproute'
var exec = require('child_process').exec
let route = {
type: 'unicast',
to: '224.0.0.0/4',
scope: 'link'
}
export function add(args, callback) {
route.dev = args.interface
if (process.platform == 'darwin') {
exec(`sudo route -nv add -net ${route.to} -interface ${route.dev}`, function(err, stdout, stderr) {
if (err) console.log(err)
if (typeof callback == 'function') callback()
})
return
}
iproute.route.add(route, (err) => {
if (err) console.log(err)
if (typeof callback == 'function') callback()
})
}
export function del(args, callback) {
route.dev = args.interface
if (process.platform == 'darwin') {
exec(`sudo route -v delete -inet ${route.to} -interface ${route.dev}`, function(err, stdout, stderr) {
if (err) console.log(err)
if (typeof callback == 'function') callback()
})
return
}
iproute.route.delete(route, (err) => {
if (err) console.log(err)
if (typeof callback == 'function') callback()
})
}