import socket
import fcntl
import struct


def get_ip_address(network_iface):
    """
    Returns the ip address of a specific network interface. Returns None if
    it could not be determined.
    """
    try:
        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        return socket.inet_ntoa(fcntl.ioctl(
            s.fileno(), 0x8915, struct.pack('256s', network_iface[:15].encode('utf-8'))
        )[20:24])
    except:
        return None