📅  最后修改于: 2022-03-11 14:46:44.391000             🧑  作者: Mango
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