[Linux] Always look up ipv4 address with localip

This commit is contained in:
Ivan Malison 2018-06-18 14:33:55 -07:00
parent 8e58adc890
commit 3b2eccfa64
No known key found for this signature in database
GPG Key ID: 62530EFBE99DC2F8

View File

@ -459,7 +459,10 @@ function localip {
ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1'
;;
'Linux')
hostname --ip-address
ip -4 addr | grep -oP '(?<=inet\s)\d+(\.\d+){3}' | grep -v 127.0.0.1 | head -n 1
# This was a nicer solution, but it returns ipv6 addresses on
# machines that have them:
# hostname --ip-address
;;
esac
}