import socket
import struct


def ipv4_to_long(ip):
    """Return the IPv4 address string as a long

    >>> ipv4_to_long("127.0.0.1")
    2130706433L
    >>> ipv4_to_long("1.2.3.4")
    16909060L
    """
    ip_bytes_n = socket.inet_pton(socket.AF_INET, ip)
    return int(struct.unpack('!I', ip_bytes_n)[0])