Last active
June 15, 2017 19:29
-
-
Save jlongman/92289cf3260ff926418361607d0dd26c to your computer and use it in GitHub Desktop.
Status, stop, reload and separate start of proxy for MacOS
This file contains 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
/** | |
* Created by jonathan.longman on 2017-06-15. | |
*/ | |
var list = [ | |
"www.foo.com", | |
"bar.com" | |
]; | |
// searches as substring now | |
function FindProxyForURL(url, host) { | |
for (var i = list.length - 1; i >= 0; i--) { | |
if (host.indexOf(list[i]) > -1) { | |
return "PROXY 127.0.0.1:8080"; | |
} | |
} | |
return "DIRECT"; | |
}; | |
//ret = FindProxyForURL(url, host); |
This file contains 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
#!/bin/bash -u | |
me="`basename $0`" | |
if [[ $1 == "start" ]]; then | |
echo "This script doesn't do start - too ambiguous"; | |
exit 2; | |
fi | |
if [[ $1 != "stop" ]] && [[ $1 != "reload" ]] ; then | |
networksetup -listallnetworkservices | awk 'NR>1' | while read SERVICE ; do | |
echo $SERVICE: | |
networksetup -getautoproxyurl "$SERVICE"| sed -e 's/^/ /' | |
done | |
exit 0; | |
fi | |
if [[ $EUID -ne 0 ]]; then | |
echo "This script must be run as root" 1>&2 | |
exit 1 | |
fi | |
verb="" | |
networksetup -listallnetworkservices | awk 'NR>1' | while read SERVICE ; do | |
if networksetup -getautoproxyurl "$SERVICE" | grep '^Enabled: Yes' >/dev/null; then | |
if [[ "$1" == "reload" ]] || [[ "$1" == "stop" ]]; then | |
verb="stopped" | |
networksetup -setautoproxystate "$SERVICE" off | |
fi | |
if [[ "$1" == "reload" ]] ; then | |
verb="restarted" | |
networksetup -setautoproxystate "$SERVICE" on | |
fi | |
echo "$SERVICE" $verb. | |
fi | |
done | |
This file contains 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
#!/bin/bash -u | |
SERVICE="USB 10/100/1000 LAN" | |
URL="file://$HOME/workspace/proxy.pac" | |
if curl --silent --output /dev/null --head --fail "$URL" ; then | |
# works - note we don't need it, just testing it | |
echo -e ... | |
else | |
# no works | |
echo link not found: $? : $URL | |
fi | |
if [[ $EUID -ne 0 ]]; then | |
echo "This script must be run as root" 1>&2 | |
exit 1 | |
fi | |
if networksetup -getautoproxyurl "$SERVICE" | grep -v '^URL: '"$URL" >/dev/null; then | |
networksetup -setautoproxyurl "$SERVICE" $URL | |
echo -e "$SERVICE" set to $URL | |
fi | |
if networksetup -getautoproxyurl "$SERVICE" | grep '^Enabled: No' >/dev/null; then | |
networksetup -setautoproxystate "$SERVICE" on | |
echo "$SERVICE" started and set to $URL | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This manages the proxy connection for a Mac when doing testing when using cool things like mitmproxy.
Much easier than using the Control Panel.