interface name & IP address using psutil

29 views
Skip to first unread message

nilesh bhadane

unread,
Dec 3, 2018, 5:58:36 PM12/3/18
to psutil
I have written a simple program using psutil to get interface IP address and interface name 

def get_int_ip():
    ifaces = psutil.net_if_addrs()
    for k, v in ifaces.items():
        ip = v[0].address
        print("IP : " + ip + " name = " + k)

is this correct program?
will it work for Ubuntu & FreeBSD?

 ip = v[0].address .  -> Using 0th index to get ip address. Is this right?

Thanks,
Nilesh


Reply all
Reply to author
Forward
0 new messages