Created
August 30, 2013 13:29
-
-
Save paulc/6389862 to your computer and use it in GitHub Desktop.
Grab FreeBSD network settings
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
_check() { | |
[ "$1" = "-echo" ] && shift && local _echo=1 | |
local _var="$1" | |
local _msg="$2" | |
local _default="$3" | |
local _r | |
if [ ${#_default} -gt 0 ] | |
then | |
read -p "${_msg} [${_default}]: " _r | |
else | |
read -p "${_msg}: " _r | |
fi | |
eval ${_var}=\"${_r:-${_default}}\" | |
[ "${_echo}" = 1 ] && eval echo \$${_var} | |
} | |
_check HOSTNAME "Hostname" $(hostname) | |
_check EXT_IF "External Interface" $(route -n get -inet default | awk '/interface:/ { print $2 }') | |
_check IPV4 "IPv4 Address" $(ifconfig $EXT_IF | awk '/inet[^6]/ { print $2; exit }') | |
_check IPV4_MASK "IPv4 Netmask" $(ifconfig $EXT_IF | awk '/inet[^6]/ { print $4; exit }') | |
_check IPV4_GW "IPv4 Default Gateway" $(route -n get -inet default | awk '/gateway:/ { print $2 }') | |
_check IPV6 "IPv6 Address" $(ifconfig $EXT_IF | awk '/inet6/ { if ( substr($2,0,4) != "fe80" ) { print $2; exit } }') | |
_check IPV6_PREFIX "IPv6 Prefix Length" $(ifconfig $EXT_IF | awk '/inet6/ { if ( substr($2,0,4) != "fe80" ) { print $4; exit } }') | |
_check GATEWAYV6 "IPv6 Default Gateway" $(route -n get -inet6 default | awk '/gateway:/ { print $2 }') | |
cat <<EOM | |
HOSTNAME : $HOSTNAME | |
EXT_IF : $EXT_IF | |
IPV4 : $IPV4 | |
IPV4_MASK : $IPV4_MASK | |
IPV4_GW : $IPV4_GW | |
IPV6 : $IPV6 | |
IPV6_PREFIX : $IPV6_PREFIX | |
GATEWAYV6 : $GATEWAYV6 | |
EOM |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment