📅  最后修改于: 2022-03-11 14:51:12.142000             🧑  作者: Mango
# The original web page offers a few alternatives. This one seems to be easy to understand, replicate and customize
# It will grab the first non 'localhost' and non 'ipv6' address
IP=$(ifconfig | grep -e 'inet' | grep -v 'inet6' | grep -v '127.0.0.1' | head -n 1 | awk '{print $2}')
# However, sometime it returns a 192.168.x.x type of address.
# In which case, this will return the public IP
IP=$(ip route get 8.8.8.8 | awk '{print $3}')