Skip to content

Instantly share code, notes, and snippets.

@alecthegeek
Created November 1, 2014 00:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alecthegeek/7ce648936a92d66029c9 to your computer and use it in GitHub Desktop.
Save alecthegeek/7ce648936a92d66029c9 to your computer and use it in GitHub Desktop.
#! /usr/bin/env sh
# Set up some shit dependeing on primary mac address
if=en0 # Change this is you don't want to use primary
updateHost() {
# $1 = ip address
# $2 = hostname
# $3 = interface name
# NB Mac specific
cat <<'EOF'|sudo bash -s $1 $2 $3
ipconfig set $3 INFORM $1
hostname $2
scutil --set HostName $(hostname)
scutil --set LocalHostName $(hostname)
EOF
}
mac=$(ifconfig $if | sed -Ene '/^[[:blank:]]ether[[:blank:]]+([0-9a-f:]+)[[:blank:]]*$/s//\1/p')
case $mac in
aa:bb:cc:49:5e:23) updateHost 192.168.1.51 hostname1 $if ;;
11.22:33:44:55:66) updateHost 192.168.1.52 hostname2 $if ;;
*) echo Error MAC Address $mac not recognised
esac
echo Mac address is \"$mac\"
echo IP Address is $(ifconfig $if | sed -Ene '/inet (.+)$/s//\1/p')
echo Hostname is $(hostname)
echo Hostname os $(scutil --get HostName)
echo LocaltHostname os $(scutil --get LocalHostName)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment