def GetAdaptersAddresses(AF=AF_UNSPEC):
    """Return all Windows Adapters addresses from iphlpapi"""
    # We get the size first
    size = ULONG()
    flags = GAA_FLAG_INCLUDE_PREFIX
    res = _GetAdaptersAddresses(AF, flags,
                                None, None,
                                byref(size))
    if res != 0x6f:  # BUFFER OVERFLOW -> populate size
        raise RuntimeError("Error getting structure length (%d)" % res)
    # Now let's build our buffer
    pointer_type = POINTER(IP_ADAPTER_ADDRESSES)
    buffer = create_string_buffer(size.value)
    AdapterAddresses = ctypes.cast(buffer, pointer_type)
    # And call GetAdaptersAddresses
    res = _GetAdaptersAddresses(AF, flags,
                                None, AdapterAddresses,
                                byref(size))
    if res != NO_ERROR:
        raise RuntimeError("Error retrieving table (%d)" % res)
    results = _resolve_list(AdapterAddresses)
    del(AdapterAddresses)
    return results
def GetAdaptersAddresses ( AF = AF_UNSPEC ) : size = ULONG ( ) flags = GAA_FLAG_INCLUDE_PREFIX res = _GetAdaptersAddresses ( AF , flags , None , None , byref ( size ) ) if res != 0x6f : raise RuntimeError ( "Error getting structure length (%d)" % res ) pointer_type = POINTER ( IP_ADAPTER_ADDRESSES ) buffer = create_string_buffer ( size . value ) AdapterAddresses = ctypes . cast ( buffer , pointer_type ) res = _GetAdaptersAddresses ( AF , flags , None , AdapterAddresses , byref ( size ) ) if res != NO_ERROR : raise RuntimeError ( "Error retrieving table (%d)" % res ) results = _resolve_list ( AdapterAddresses ) del ( AdapterAddresses ) return results
Return all Windows Adapters addresses from iphlpapi