from socket import inet_aton
from struct import unpack


def ip2long(ip_addr):
    """Converts an IP address string to an integer."""
    ip_packed = inet_aton(ip_addr)
    ip = unpack('!L', ip_packed)[0]
    return ip