Ejemplo n.º 1
0
def each(pid, el, res):
    abuf = base64.b64decode(res['abuf'])
    rr = dnslib.DNSRecord.parse(abuf)

    if len(rr.rr) < 2 or not rr.rr[1].rdata: return fail()
    ip = str(rr.rr[1].rdata)
    asn, name = libgeoip.lookup(ip)

    return "%.1f,%s,%d,%s" % (res['rt'], common.safe(ip), asn, name)
Ejemplo n.º 2
0
def each(pid, el, res):
    abuf = base64.b64decode(res['abuf'])
    rr = dnslib.DNSRecord.parse(abuf)
    if len(rr.rr) < 1 or not rr.rr[0].rdata: return fail()
    j = json.loads(str(rr.rr[0].rdata)[1:-1])
    ip = j['ip']
    asn, name = libgeoip.lookup(ip)

    return "%.1f,%s,%d,%s" % (res['rt'], ip, asn, name)
Ejemplo n.º 3
0
def each(pid, el, res):
    abuf = base64.b64decode(res['abuf'])
    rr = dnslib.DNSRecord.parse(abuf)

    ip = str(rr.a.rdata)
    asn, name = libgeoip.lookup(ip)

    return "%.1f,%d,%d,%d,%s,%d,%s" % (res['rt'], res['size'],
                                       rr.header.bitmap, rr.header.rcode,
                                       common.safe(ip), asn, name)
Ejemplo n.º 4
0
def each(pid, el, res):
    # for tracking
    hops = []
    aspath = []
    hopcount = 0
    lastx = False

    # go through all hops
    for hop in res:
        if "result" not in hop: continue

        # find the min rtt hop details
        mrtt = -1.0
        mip = None
        for mes in hop["result"]:
            if "rtt" not in mes:
                if mrtt >= 0.0: continue
                if "from" in mes:
                    mip = mes["from"]
                else:
                    mip = "*"
            elif mrtt < 0 or mes["rtt"] < mrtt:
                mrtt = mes["rtt"]
                mip = mes["from"]

        # not found? go to next hop
        if not mip: continue

        # * again?
        if mip == "*":
            if lastx: continue
            lastx = True

        # private addr?
        if mip.startswith(private_ips): continue

        # add to hops[]
        hops.append((mrtt, mip))

    # convert hops to aspath
    last_org = "?"
    last_rtt = -1
    for hop in hops:
        rtt, ip = hop
        if ip == "*": continue

        asn, name = libgeoip.lookup(ip)

        # add?
        if last_org != name:
            aspath.append((rtt, ip, asn, name))
            last_org = name
            last_rtt = rtt
        elif name != "?" and last_rtt < rtt:
            aspath.pop()
            aspath.append((rtt, ip, asn, name))
            last_rtt = rtt

    # hop count
    if len(hops) == 0:
        hopcount = -1
    elif hops[-1][1] == "*":
        hopcount = -1
    else:
        hopcount = len(hops)

    # aspath len
    if len(aspath) == 0:
        aslen = -1
    elif aspath[-1][2] == -1:
        aslen = -1
    else:
        aslen = len(aspath)

    # last known asnum, name, and rtt
    ntl_rtt, ntl_ip, ntl_asn, ntl_name = -1, "", -1, "?"
    for i in range(2, len(aspath) + 1):
        ntl_rtt, ntl_ip, ntl_asn, ntl_name = aspath[-i]
        if ntl_asn != -1: break

    return "%d,%d,%.1f,%d,%s" % (hopcount, aslen, ntl_rtt, ntl_asn, ntl_name)
Ejemplo n.º 5
0
def each(pid, el, res):
	ip = el["from"] if "from" in el else "?"
	asn, name = libgeoip.lookup(ip)

	return "%.1f,%s,%d,%s" % (el["min"], ip, asn, name)