1from netifaces import interfaces, ifaddresses, AF_INET
2for ifaceName in interfaces():
3 addresses = [i['addr'] for i in ifaddresses(ifaceName).setdefault(AF_INET, [{'addr':'No IP addr'}] )]
4 print('%s: %s' % (ifaceName, ', '.join(addresses)))
5
6>>>
7 lo: 127.0.0.1
8 enp30s0: No IP addr
9 wlp31s0: 192.168.1.56