def getifaddrs():
 libc = ctypes.CDLL(ctypes.util.find_library('c'))
 getifaddrs = libc.getifaddrs
 getifaddrs.restype = ctypes.c_int
 getifaddrs.argtpes = [ctypes.POINTER(ctypes.POINTER(struct_ifaddrs))]
 freeifaddrs = libc.freeifaddrs
 freeifaddrs.restype = None
 freeifaddrs.argtypes = [ctypes.POINTER(struct_ifaddrs)]
 ifaptr = ctypes.POINTER(struct_ifaddrs)()
 result = getifaddrs(ctypes.pointer(ifaptr))
 if (result == (-1)):
  raise OSError(ctypes.get_errno())
 del result
 try:
  ifas = []
  while ifaptr:
   ifac = ifaptr.contents
   ifa = {'name': ifac.ifa_name, 'flags': ifac.ifa_flags}
   if ifac.ifa_addr:
    (ifa['family'], ifa['addr']) = sockaddr_fixup(ifac.ifa_addr)
   else:
    (ifa['family'], ifa['addr']) = (None, None)
   if ifac.ifa_netmask:
    (_, ifa['netmask']) = sockaddr_fixup(ifac.ifa_netmask)
   else:
    ifa['network'] = None
   ifas.append(ifa)
   ifaptr = ifac.ifa_next
  return ifas
 finally:
  freeifaddrs(ifaptr)

def getifaddrs ( ) : libc = ctypes . CDLL ( ctypes . util . find_library ( 'c' ) ) getifaddrs = libc . getifaddrs getifaddrs . restype = ctypes . c_int getifaddrs . argtpes = [ ctypes . POINTER ( ctypes . POINTER ( struct_ifaddrs ) ) ] freeifaddrs = libc . freeifaddrs freeifaddrs . restype = None freeifaddrs . argtypes = [ ctypes . POINTER ( struct_ifaddrs ) ] ifaptr = ctypes . POINTER ( struct_ifaddrs ) ( ) result = getifaddrs ( ctypes . pointer ( ifaptr ) ) if ( result == ( - 1 ) ) : raise OSError ( ctypes . get_errno ( ) ) del result try : ifas = [ ] while ifaptr : ifac = ifaptr . contents ifa = { 'name' : ifac . ifa_name , 'flags' : ifac . ifa_flags } if ifac . ifa_addr : ( ifa [ 'family' ] , ifa [ 'addr' ] ) = sockaddr_fixup ( ifac . ifa_addr ) else : ( ifa [ 'family' ] , ifa [ 'addr' ] ) = ( None , None ) if ifac . ifa_netmask : ( _ , ifa [ 'netmask' ] ) = sockaddr_fixup ( ifac . ifa_netmask ) else : ifa [ 'network' ] = None ifas . append ( ifa ) ifaptr = ifac . ifa_next return ifas finally : freeifaddrs ( ifaptr )
getifaddrs() -> dict list a wrapper for libcs getifaddrs .