-
Notifications
You must be signed in to change notification settings - Fork 0
/
socksproxy
executable file
·42 lines (38 loc) · 1.24 KB
/
socksproxy
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
39
40
41
42
#!/usr/bin/env node
var SERVER = 'localhost',
PORT = 1080,
INTERFACE = 'Wi-Fi',
state = process.argv[2],
command;
var exec = require('child_process').exec;
if (state === 'on') {
command = ['networksetup -setsocksfirewallproxy', INTERFACE, SERVER, PORT].join(' ');
exec(command, function (err) {
if (!err) {
console.log('============================');
console.log('SOCKS proxy enabled');
console.log('============================');
}
printSocksProxyStatus();
});
} else if (state === 'off') {
command = ['networksetup -setsocksfirewallproxystate', INTERFACE, 'off'].join(' ');
exec(command, function (err) {
if (!err) {
console.log('============================');
console.log('SOCKS proxy disabled');
console.log('============================');
}
printSocksProxyStatus();
});
} else {
console.log('Usage:');
console.log(' $ socksproxy on');
console.log(' $ socksproxy off');
}
function printSocksProxyStatus () {
command = 'networksetup -getsocksfirewallproxy ' + INTERFACE;
exec(command, function (err, stdout, stderr) {
console.log(stdout);
});
}