Ejemplo n.º 1
0
def lookup():
    reader = open('md_ip_build', 'r')
    writer = open('md_bar.result', 'w')
    for line in reader:
        line = line[0:len(line)-1]
        dn_ips = line.split(' ')
        ips = dn_ips[1:len(dn_ips)]
        asn = []
        prefix = []
        cc = []
        lir = []
        date = []
        owner=[]
        for ip in ips:
            c = Client()
            result = c.lookup(ip, qType='IP')
            asn.append(result.asn)
            prefix.append(result.prefix)
            cc.append(result.cc)
            lir.append(result.lir)
            date.append(result.date)
        asn_num = set(asn)
        print(asn_num)
        for num in asn_num:
            if num == None:
                continue
            c = Client()
            if ' ' not in num:
                result = c.lookup(num[2:], qType='ASN')
                owner.append(result.owner)
            else:
                num = num[2:]
                nums = num.split(' ')
                print(nums)
                for n in nums:
                    result = c.lookup(n, qType='ASN')
                    owner.append(result.owner)

        writer.write(dn_ips[0])
        writer.write(' ')
        writer.write(str(len(set(asn))))
        writer.write(' ')
        writer.write(str(len(set(prefix))))
        writer.write(' ')
        writer.write(str(len(set(cc))))
        writer.write(' ')
        writer.write(str(len(set(lir))))
        writer.write(' ')
        writer.write(str(len(set(date))))
        writer.write(' ')
        writer.write(str(len(set(owner))))
        writer.write('\n')
    reader.close()
    writer.close()
Ejemplo n.º 2
0
def diff_build(ips_former, ips_backer):
    ips = ips_backer | ips_former
    if len(ips) > 200:
        return [0.0] * 5
    print(len(ips))

    asn_former = []
    asn_backer = []
    bgp_former = []
    bgp_backer = []
    cc_former = []
    cc_backer = []
    lir_former = []
    lir_backer = []
    date_former = []
    date_backer = []
    for ip in ips:
        c = Client()
        r = c.lookup(ip, qType='IP')
        if ip in ips_former:
            asn_former.append(r.asn)
            bgp_former.append(r.prefix)
            cc_former.append(r.cc)
            lir_former.append(r.lir)
            date_former.append(r.date)

        if ip in ips_backer:
            asn_backer.append(r.asn)
            bgp_backer.append(r.prefix)
            cc_backer.append(r.cc)
            lir_backer.append(r.lir)
            date_backer.append(r.date)

    ip_count = float(len(ips))
    diff = []
    diff.append(len(set(asn_former) ^ set(asn_backer)))
    diff.append(len(set(bgp_former) ^ set(bgp_backer)))
    diff.append(len(set(cc_former) ^ set(cc_backer)))
    diff.append(len(set(lir_former) ^ set(lir_backer)))
    diff.append(len(set(date_former) ^ set(date_backer)))
    return [x / ip_count for x in diff]
Ejemplo n.º 3
0
def diff_build(ips_former, ips_backer):
    ips = ips_backer | ips_former
    if len(ips) > 200:
        return [0.0]*5
    print(len(ips))

    asn_former = []
    asn_backer = []
    bgp_former = []
    bgp_backer = []
    cc_former = []
    cc_backer = []
    lir_former = []
    lir_backer = []
    date_former = []
    date_backer = []
    for ip in ips:
        c = Client()
        r = c.lookup(ip, qType='IP')
        if ip in ips_former:
            asn_former.append(r.asn)
            bgp_former.append(r.prefix)
            cc_former.append(r.cc)
            lir_former.append(r.lir)
            date_former.append(r.date)

        if ip in ips_backer:
            asn_backer.append(r.asn)
            bgp_backer.append(r.prefix)
            cc_backer.append(r.cc)
            lir_backer.append(r.lir)
            date_backer.append(r.date)

    ip_count = float(len(ips))
    diff = []
    diff.append(len(set(asn_former) ^ set(asn_backer)))
    diff.append(len(set(bgp_former) ^ set(bgp_backer)))
    diff.append(len(set(cc_former)  ^ set(cc_backer)))
    diff.append(len(set(lir_former) ^ set(lir_backer)))
    diff.append(len(set(date_former) ^ set(date_backer)))
    return [x/ip_count for x in diff]