get ip address

Solutions on MaxInterview for get ip address by the best coders in the world

showing results for - "get ip address"
Vincenzo
13 Sep 2019
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