Created
November 1, 2014 00:45
-
-
Save alecthegeek/7ce648936a92d66029c9 to your computer and use it in GitHub Desktop.
Set ip info based on mac addess https://plus.google.com/u/0/108968986881529941950/posts/jd2sKgWjm3k
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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