Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 43 lines (38 sloc) 1.24 KB
#!/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);
});
}