Show external ipv4 address on about screen

This commit is contained in:
Bob Mottram 2017-09-25 11:10:26 +01:00
parent 021a850a5e
commit aec19a4876
2 changed files with 9 additions and 4 deletions

View File

@ -519,7 +519,7 @@ function show_ip_addresses {
echo $'IP/DNS addresses'
echo '================'
echo ''
echo -n "IPv4: $(get_ipv4_address)"
echo -n "IPv4: $(get_ipv4_address)/$(get_external_ipv4_address)"
ipv6_address="$(get_ipv6_address)"
if [ ${#ipv6_address} -gt 0 ]; then
echo " IPv6: ${ipv6_address}"

View File

@ -31,11 +31,12 @@
# If the system is on an IPv6 network
IPV6_NETWORK='2001:470:26:307'
# Destinations used to get the external IP address of this system
# Google ipv6 DNS is 2001:4860:4860::8888
# Destinations used to get the local IP address of this system
# Google ipv6 DNS 2001:4860:4860::8888
# OpenDNS ipv6 DNS 2620:0:ccc::2
IPV4_ADDRESS_TEST_DESTINATION='85.214.73.63'
IPV6_ADDRESS_TEST_DESTINATION='2620:0:ccc::2'
EXTERNAL_IP_LOOKUP_URL='ifcfg.me'
# The static IP address of the system within the local network
# By default the IP address is dynamic within your LAN
@ -70,6 +71,10 @@ function install_static_network {
mark_completed $FUNCNAME
}
function get_external_ipv4_address {
nslookup . $EXTERNAL_IP_LOOKUP_URL | grep Address | tail -n 1 | awk -F ' ' '{print $2}'
}
function get_ipv4_address {
IPv4dev=$(ip route get $IPV4_ADDRESS_TEST_DESTINATION | awk '{for(i=1;i<=NF;i++)if($i~/dev/)print $(i+1)}')
echo $(ip -o -f inet addr show dev "$IPv4dev" | awk '{print $4}' | awk 'END {print}' | awk -F '/' '{print $1}')