Last active
September 29, 2015 01:43
-
-
Save isao/12148eca5d627b2059c9 to your computer and use it in GitHub Desktop.
Display the *local* IP address of the active network interface.
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
#!/bin/sh -eu | |
get_interface() | |
{ | |
route get 0.0.0.0 2>/dev/null | awk '/interface: /{print $2}' | |
} | |
get_ip() | |
{ | |
ifconfig -r $1 | awk '/inet /{print $2}' | |
} | |
# The _local_ IP of the current active network interface. | |
get_ip $(get_interface) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment