コード例 #1
0
def get_nsa_flag(ipInfo=None, ip=None, conn=None, long_lat=None):
    if not ixmaps.is_nsa(ipInfo, ip, conn, long_lat):
        return "clear"

    else:
        return ("nsa_class_" +
                ixmaps.get_nsa_class(ipInfo, ip, conn, long_lat))
コード例 #2
0
def add_traceroutes (conn, new_traceroutes_db, be_verbose=False):
    lock=MutexFile(LOCK_FILE)
    if not lock.acquire ():
        return False

    if not conn:
        conn = ixmaps.DBConnect.getConnection()
    
    new_traceroutes = new_traceroutes_db.dictresult()

    insert_into_traits = ""
    insert_into_countries = ""

    for traceroute in new_traceroutes:

        traceroute_id = traceroute['id']

        if be_verbose:
            print traceroute_id

        qres = conn.query ("select * from tr_item where traceroute_id=%i" 
                            % traceroute_id)

        tr_body = qres.dictresult()

        if not tr_body: continue

        (nhops, nattempts) = get_tr_items_dim (tr_body)

        ipaddrs = [None] * nhops
        # ip_info = [None] * nhops

        # print "tr_body:" , tr_body

        for probe in tr_body:
            # print "    probe['hop']:", probe['hop']
            hop = probe['hop']-1

            # --- There are multiple attempts for each hop, but we
            #     only need one, so, after you aquire an IP, ignore
            #     further attempts ---
            if (ipaddrs[hop]):
                continue     
            ipaddrs[hop] = probe['ip_addr']

        # for hop in range (nhops):
            # ip_info[hop] = ixmaps.get_ip_addr_info (ipaddrs[hop], conn)

        ip_info = get_ip_addr_info_list (ipaddrs, conn)

        number_of_ips = len(ip_info)

        is_nsa = False
        # print "ip_info:", ip_info
        # print "len(ip_info):", len (ip_info)
        # print "len(ipaddrs):", len(ipaddrs)
        # print "ipaddrs:", ipaddrs
        # print "number_of_ips:", number_of_ips

        # print "for hop in range (number_of_ips):"
        for hop in range (number_of_ips):
            # print '    ipaddrs[' + str(hop) + ']:', ipaddrs[hop]
            pr_addr = ipaddrs[hop]
            # print (ip_info[hop])
            is_nsa = ixmaps.is_nsa(ip_info[hop])
            # print "    is_nsa:", is_nsa
            if is_nsa == True:
                break

        is_chotel = False
        # print "for hop in range (number_of_ips):"
        for hop in range (number_of_ips):
            pr_addr = ipaddrs[hop]
            # print "    ip_info[" + str(hop) + "]: ", ip_info[hop]
            is_chotel = ixmaps.is_chotel(ip_info[hop])
            if is_chotel == True:
                break

        canada_flag = False
        us_flag = False
        for hop in range (number_of_ips):
            pr_addr = ipaddrs[hop]
            country = ixmaps.get_country (ip_info[hop])
            if country == "CA":
                canada_flag = True
            if country == "US":
                us_flag = True
            if (canada_flag == True) and (us_flag == True):
                break

        # --- Remove, so as not to get an SQL error, just in case some
        #     traits-data for this traceroute already exists ---
        conn.query ("delete from traceroute_traits where id = %i" % traceroute_id)
        conn.query ("""insert into traceroute_traits (id, nsa, hotel)
        values (%i, %s, %s)""" % (traceroute_id, is_nsa, is_chotel))

        # --- Remove, so as not to get an SQL error, just in case some
        #     country-data for this traceroute already exists ---
        if canada_flag or us_flag:
            conn.query("delete from traceroute_countries where traceroute_id = %s" \
                       % (traceroute_id) )

            if canada_flag:
                conn.query ("""insert into traceroute_countries (country_code, traceroute_id)
                values ('CA', %i)""" % traceroute_id)
            if us_flag:
                conn.query ("""insert into traceroute_countries (country_code, traceroute_id)
                values ('US', %i)""" % traceroute_id)

    return True
コード例 #3
0
def get_nsa_flag (ipInfo=None, ip=None, conn=None, long_lat=None):
    if not ixmaps.is_nsa (ipInfo, ip, conn, long_lat):
        return "clear"

    else:
        return ( "nsa_class_" + ixmaps.get_nsa_class (ipInfo, ip, conn, long_lat) )