def parseline(line):
    sline = line.split()
    if (len(sline) < 11):
        return None
    m = PATTERN_IPV4.match(sline[0])
    sortkey = None
    ip = None
    if (m is None):
        m = PATTERN_IPV6.match(sline[0])
        if (m is None):
            m = PATTERN_ONION.match(sline[0])
            if (m is None):
                return None
            else:
                net = 'onion'
                ipstr = sortkey = m.group(1)
                port = int(m.group(2))
        else:
            net = 'ipv6'
            if (m.group(1) in ['::']):
                return None
            ipstr = m.group(1)
            sortkey = ipstr
            port = int(m.group(2))
    else:
        ip = 0
        for i in range(0, 4):
            if ((int(m.group((i + 2))) < 0) or (int(m.group((i + 2))) > 255)):
                return None
            ip = (ip + (int(m.group((i + 2))) << (8 * (3 - i))))
        if (ip == 0):
            return None
        net = 'ipv4'
        sortkey = ip
        ipstr = m.group(1)
        port = int(m.group(6))
    if (sline[1] == 0):
        return None
    uptime30 = float(sline[7][:(- 1)])
    lastsuccess = int(sline[2])
    version = int(sline[10])
    if (len(sline) > 11):
        agent = (sline[11][1:] + sline[12][:(- 1)])
    else:
        agent = sline[11][1:(- 1)]
    service = int(sline[9], 16)
    blocks = int(sline[8])
    return {'net': net, 'ip': ipstr, 'port': port, 'ipnum': ip, 'uptime': uptime30, 'lastsuccess': lastsuccess, 'version': version, 'agent': agent, 'service': service, 'blocks': blocks, 'sortkey': sortkey}
def parseline(line):
    sline = line.split()
    if (len(sline) < 11):
        return None
    m = PATTERN_IPV4.match(sline[0])
    sortkey = None
    ip = None
    if (m is None):
        m = PATTERN_IPV6.match(sline[0])
        if (m is None):
            m = PATTERN_ONION.match(sline[0])
            if (m is None):
                return None
            else:
                net = 'onion'
                ipstr = sortkey = m.group(1)
                port = int(m.group(2))
        else:
            net = 'ipv6'
            if (m.group(1) in ['::']):
                return None
            ipstr = m.group(1)
            sortkey = ipstr
            port = int(m.group(2))
    else:
        ip = 0
        for i in range(0, 4):
            if ((int(m.group((i + 2))) < 0) or (int(m.group((i + 2))) > 255)):
                return None
            ip = (ip + (int(m.group((i + 2))) << (8 * (3 - i))))
        if (ip == 0):
            return None
        net = 'ipv4'
        sortkey = ip
        ipstr = m.group(1)
        port = int(m.group(6))
    if (sline[1] == 0):
        return None
    uptime30 = float(sline[7][:(- 1)])
    lastsuccess = int(sline[2])
    version = int(sline[10])
    if (len(sline) > 11):
        agent = (sline[11][1:] + sline[12][:(- 1)])
    else:
        agent = sline[11][1:(- 1)]
    service = int(sline[9], 16)
    blocks = int(sline[8])
    return {'net': net, 'ip': ipstr, 'port': port, 'ipnum': ip, 'uptime': uptime30, 'lastsuccess': lastsuccess, 'version': version, 'agent': agent, 'service': service, 'blocks': blocks, 'sortkey': sortkey}