Getting IP address from shell
Thursday, September 9th, 2010So someone asked earlier on one of the social networking sites I follow how to get the ip address from the shell, here are two quick and dirty ways (using just cmd line utils that could be utilized from shell) – Use at your own risk :).
Linux: - You can specify a device or if you do not it returns them all. ifconfig | grep inet | awk -F: '{print $2}' | grep -i bcast | sed -e '/Bcast//g' Output: $> ifconfig | grep inet | awk -F: '{print $2}' | grep -i bcast | sed -e 's/Bcast//g' 192.168.1.2 192.168.1.3 or OSX / BSD: - If you leave off the final grep it will return then all (IPv6 as well) ifconfig | grep inet | awk '{print $2}' | grep -v [:num:] (greps out everything but numbers, grep -v [:digit:] works as well) Output: $> ifconfig | grep inet | awk '{print $2}' | grep -v [:num:] 127.0.0.1 192.168.1.3
