-
-
Save lira/dc9ed869ac2be1a2e1114c6c9e98d504 to your computer and use it in GitHub Desktop.
Redirect HTTP traffic on Internet Sharing to a local Charles proxy
This file contains hidden or 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
#!/usr/bin/env node | |
var options = require('minimist')(process.argv.slice(2), { default: { | |
cport: 8888 | |
}}); | |
var disable = options.disable || options.d; | |
var enable = options.enable || options.e; | |
var status = options.s || options.status; | |
var child = require('child_process'); | |
// -s or --status to list active rules | |
if (status) { | |
child.exec('sudo pfctl -s nat -i bridge100', function (error, stdout, stderror) { | |
console.log(stdout || stderror); | |
}); | |
return; | |
} | |
if (enable) { | |
var pfrules = [ | |
'rdr pass on bridge100 inet proto tcp from any to any port 80 -> 127.0.0.1 port {charles_port}', | |
]; | |
pfrules.forEach(function (pfrule) { | |
pfrule = pfrule.replace(/{charles_port}/g, options.cport); | |
child.exec('echo "' + pfrule + '" | sudo pfctl -ef -'); | |
}); | |
console.log('HTTP & HTTPS traffic on Internet Sharing network now redirecting to 127.0.0.1:' + options.cport); | |
return; | |
} else if (disable) { | |
console.log('Cleared all rules on the Internet Sharing network'); | |
child.exec('sudo pfctl -F nat -i bridge100'); | |
return; | |
} | |
console.log('Usage: -e to enable, -d to disable or -s for status'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment