Answers for "Get IP address"

0

Get IP address

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
Posted by: Guest on July-20-2021

Python Answers by Framework

Browse Popular Code Answers by Language