Skip to content

Instantly share code, notes, and snippets.

@Farhaduneci
Last active November 17, 2023 13:44
Show Gist options
  • Save Farhaduneci/4b3d5065a283f18be6533ec461373be5 to your computer and use it in GitHub Desktop.
Save Farhaduneci/4b3d5065a283f18be6533ec461373be5 to your computer and use it in GitHub Desktop.
Mac Proxy Configuration Script

ProxyPilot

My Mac Proxy Configuration Script.

Overview

This is a friendly and simple script for macOS users to manage proxy settings. Whether you need to quickly switch on your proxies for secure browsing or disable them when not needed, this script makes it a breeze!

How to Use

  • Set Proxies: ./set_proxy.sh <port-number> [server-address]
  • Unset Proxies: ./set_proxy.sh off

Getting Started

  1. Download the script.
  2. Make it executable with chmod +x set_proxy.sh.
  3. Run it and easily manage your Mac's proxy settings!

Questions, suggestions, or contributions? Feel free to comment. Happy proxy managing! 🚀

#!/bin/bash
DEFAULT_SERVER="127.0.0.1"
set_proxies() {
local server="${2:-$DEFAULT_SERVER}"
local port=$1
echo "Setting proxies to $server:$port..."
sudo networksetup -setwebproxy "Wi-Fi" $server $port
sudo networksetup -setsecurewebproxy "Wi-Fi" $server $port
sudo networksetup -setsocksfirewallproxy "Wi-Fi" $server $port
echo "Proxies set to $server:$port."
}
unset_proxies() {
echo "Unsetting proxies..."
sudo networksetup -setwebproxystate "Wi-Fi" off
sudo networksetup -setsecurewebproxystate "Wi-Fi" off
sudo networksetup -setsocksfirewallproxystate "Wi-Fi" off
echo "Proxies have been turned off."
}
if [ $# -lt 1 ]; then
echo "Usage: $0 [off|port number] [server address (optional, default: $DEFAULT_SERVER)]"
exit 1
fi
case $1 in
off)
unset_proxies
;;
*[!0-9]* | '')
echo "Please provide a valid port number or 'off' to unset proxies."
;;
*)
set_proxies $1 $2
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment