Skip to content

Instantly share code, notes, and snippets.

@gabrielfalcao
Created October 24, 2015 03:03
Show Gist options
  • Save gabrielfalcao/3a43ca67b170149bf8ed to your computer and use it in GitHub Desktop.
Save gabrielfalcao/3a43ca67b170149bf8ed to your computer and use it in GitHub Desktop.

Command-line tools for managing Mac OS networking

Connect/Disconnect from WiFi

networksetup -setairportpower en0 off
networksetup -setairportpower en0 on

List all available WiFi's

/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport scan

Forward Port 80 and 443 with Mac pfctl Port Forwarding

echo "
rdr pass inet proto tcp from any to any port 80 -> 127.0.0.1 port 8080
rdr pass inet proto tcp from any to any port 443 -> 127.0.0.1 port 8443
" | sudo pfctl -ef -

Connect to a WiFI network

networksetup -setairportnetwork <interface> <ssid> <password>

List Hardware ports

networksetup -listallhardwareports

Enable internet sharing from command line

sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.InternetSharing.plist
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment