Skip to content

Instantly share code, notes, and snippets.

@fuzzylogiq
Created August 4, 2014 15:21
Show Gist options
  • Save fuzzylogiq/3c1b27ed6b199d6628c2 to your computer and use it in GitHub Desktop.
Save fuzzylogiq/3c1b27ed6b199d6628c2 to your computer and use it in GitHub Desktop.
Script for setting network location and IP in a mixed static/dhcp environment so that imaging could take place.
#/bin/sh
function tryping {
ping -t 5 x.x.x.x > /dev/null 2>&1
if [ $? == 0 ]; then exit 0; fi
}
rm -rf /Library/Preferences/SystemConfiguration/NetworkInterfaces.plist
rm -rf /Library/Preferences/SystemConfiguration/preferences.*
networksetup -createlocation setup populate
networksetup -switchtolocation setup
# Turn off Wi-Fi
networksetup -setnetworkserviceenabled Wi-Fi off
# Find our Ethernet connection
myeth=$(networksetup -listallnetworkservices | awk '/Ethernet/ { print $0 }')
# Try the different setups
count="0"
while [ $count -lt 5 ]; do
networksetup -setmanual "$myeth" x.x.x.x x.x.x.x x.x.x.x
networksetup -setdnsservers "$myeth" x.x.x.x x.x.x.x
networksetup -setsearchdomains "$myeth" some.domain some.otherdomain
tryping
networksetup -setdhcp "$myeth"
tryping
count=$[$count+1]
done
osascript -e 'tell application "Finder" to display dialog "Unable to set network! Imaging cannot take place!"'
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment