Skip to content

Instantly share code, notes, and snippets.

@dev318
Created September 20, 2013 15:14
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dev318/6639046 to your computer and use it in GitHub Desktop.
Save dev318/6639046 to your computer and use it in GitHub Desktop.
Add a network location with manual IP info without switching to it, great for remote changes
#!/bin/bash
# purpose: add a network location with manual IP info without switching
# This script lets you fill in settings and apply them on en0(assuming that's active)
# but only interrupts current connectivity long enough to apply the settings,
# it then immediately switches back. (It also assumes a 'Static' location doesn't already exist...)
# Use at your own risk! No warranty granted or implied! Tell us we're doing it rong on twitter!
# author: Allister Banks, 318 Inc.
# set -x
declare -xr networksetup="/usr/sbin/networksetup"
declare -xr MYIP="192.168.111.177"
declare -xr MYMASK="255.255.255.0"
declare -xr MYROUTER="192.168.111.1"
declare -xr DNSSERVERS="8.8.8.8 8.8.4.4"
declare -x PORTANDSERVICE=`$networksetup -listallhardwareports | awk '/en0/{print x};{x=$0}' | cut -d ' ' -f 3`
$networksetup -createlocation "Static" populate
$networksetup -switchtolocation "Static"
$networksetup -setmanual $PORTANDSERVICE $MYIP $MYMASK $MYROUTER
$networksetup -setdnsservers $PORTANDSERVICE $DNSSERVERS
$networksetup -switchtolocation Automatic
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment