import socket


def get_integer_from_ip_str(ip_str):
    """
    Given an IP address in string format in <b>ip_str</b>, return its
    integer representation.

    Throws ValueError if the IP address string was invalid.
    """
    try:
        return socket.inet_pton(socket.AF_INET, ip_str)
    except socket.error:
        pass

    try:
        return socket.inet_pton(socket.AF_INET6, ip_str)
    except socket.error:
        pass

    # Down here, both inet_pton()s failed.
    raise ValueError("Invalid IP address string")