from ipaddress import ip_address
from urllib.parse import urlparse

tests = [
    ,
    ,
    ,
    ,
    ,
    ,
     ]

def parse_ip_port(netloc):
    try:
        ip = ip_address(netloc)
        port = None
    except ValueError:
        parsed = urlparse('
        ip = ip_address(parsed.hostname)
        port = parsed.port
    return ip, port

for address in tests:
    ip, port = parse_ip_port(address)
    hex_ip = {4:'{:08X}', 6:'{:032X}'}[ip.version].format(int(ip))
    print(.format(
        str(ip), hex_ip, ip.version, port ))