import socket
import fcntl
import struct


def get_ip_address(ifname):
    """
    Get current IP address of a network interface card

    Params
    ======
    ifname: str
        Interface name eg: eth0
    Return
    ======
    IP: str
        Current IP of the interface
    """
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    return socket.inet_ntoa(
        fcntl.ioctl(s.fileno(), 0x8915, struct.pack("256s", ifname[:15]))[20:24]  # SIOCGIFADDR
    )