mac only!!! setup proxy, type password only once
import {exec, setDialogName} from 'grant-setproxy';
// set mac os x grant dialog name
setDialogName('node-grant-setproxy');
await exec('-setwebproxystate', 'Wi-Fi', 'on');
type password once to authorize, never type again
you can find all avaliable args by typing networksetup
in the command line;
use exactly 'Wi-Fi', not 'wi-fi', you can find the exact name in network settings
exec return a Promise
, please use await
exec('-setwebproxystate', 'Wi-Fi', 'on');
exec('-setwebproxystate', 'wi-Fi', 'off');
await exec('-setwebproxystate', 'Wi-Fi', 'on');
await exec('-setwebproxystate', 'Wi-Fi', 'off');
exec('-setwebproxystate', 'Wi-Fi', 'on').then(function () {
exec('-setwebproxystate', 'Wi-Fi', 'off');
});
process.on('SIGINT', async function () {
// disable proxy when control-c
await exec('-setwebproxystate', 'Wi-Fi', 'off');
});
// set proxy to 127.0.0.1:8080
await exec('-setwebproxy', 'Wi-Fi', '127.0.0.1', '8080');