I has found a scripts from pmav99. Big thanks to him.
import socket
import psutil
def get_ip_addresses(family):
for interface, snics in psutil.net_if_addrs().items():
for snic in snics:
if snic.family == family:
yield (interface, snic.address, snic.netmask)
ipv4s = list(get_ip_addresses(socket.AF_INET))
print ipv4s
The result is :
[('Local Area Connection* 2', '169.254.189.147', '255.255.0.0'), ('Ethernet', '192.168.18.34', '255.255.255.0'), ('Wi-Fi', '192.168.1.102', '255.255.255.0'), ('Loopback Pseudo-Interface 1', '127.0.0.1', '255.0.0.0')]
But in net_if_addrs() of psutil, it also provide mac-address of each interfaces. So how can i add the mac address to the list ? the keys name of MAC addr