The Netifaces Python package provides a wealth of information about the interfaces you work with.
>>> netifaces.ifaddresses('en0') {18: [{'addr': '00:12:34:56:78:9a'}], 2: [{'broadcast': '10.255.255.255', 'netmask': '255.0.0.0', 'addr': '10.16.1.4'}], 30: [{'netmask': 'ffff:ffff:ffff:ffff::', 'addr': 'fe80::123:4567:89ab:cdef%en0'}]}
http://alastairs-place.net/projects/netifaces/
source share