$ curl 'https://api.ipify.org?format=json'
{"ip":"178.151.26.217"}
ip addr show |grep -w inet |grep -v 127.0.0.1|awk '{ print $2}'| cut -d "/" -f 1
$ curl 'https://api.ipify.org?format=json'
{"ip":"118.179.172.1"}
from netifaces import interfaces, ifaddresses, AF_INET
for ifaceName in interfaces():
addresses = [i['addr'] for i in ifaddresses(ifaceName).setdefault(AF_INET, [{'addr':'No IP addr'}] )]
print('%s: %s' % (ifaceName, ', '.join(addresses)))
>>>
lo: 127.0.0.1
enp30s0: No IP addr
wlp31s0: 192.168.1.56