Skip to content

Instantly share code, notes, and snippets.

@isao
Last active September 29, 2015 01:43
Show Gist options
  • Save isao/12148eca5d627b2059c9 to your computer and use it in GitHub Desktop.
Save isao/12148eca5d627b2059c9 to your computer and use it in GitHub Desktop.
Display the *local* IP address of the active network interface.
#!/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