Ejemplo n.º 1
0
def main1():

    d_srv = []
    fp = open('detected.txt', 'r')
    for i in fp:
        d_srv.append(i.strip())
    fp.close()

    domain = 'adfdfsfadfsf.com'
    fp_srvs = open('srv_ranking.txt', 'r')
    srvs = []
    for i in fp_srvs:
        srvs.append(i.split(' ')[0].strip())

    fp_srvs.close()

    srvs = list(set(srvs) - set(d_srv))

    print '剩余探测服务器数量:', len(srvs)
    DB = DataBase()
    DB.db_connect()
    DB.execute_no_return("USE HJ")

    random.shuffle(srvs)

    for i in srvs:
        fp_a = open('detected.txt', 'a')
        d = GetWhoisInfo(domain, i.strip()).get()
        d = d.replace("\\", "")
        d = d.replace("'", "\\'")
        d = d.replace('"', '\\"')
        SQL = """INSERT INTO {table} SET `whois_srv` = '{w}' ,`details` = '{d}' """.format(
            table=Table, w=i, d=d)
        DB.execute_no_return(SQL)
        DB.db_commit()
        fp_a.write(i + '\n')
        fp_a.close()
        print '探测完成:', i
        time.sleep(10)

    DB.db_commit()
    DB.db_close()
def TestWhoisSrv(domain, whois_srv):
    """
    测试whois服务器性能
    :param domain: 域名
    :param whois_srv: whois服务器地址 ip/whois
    :return: T - 获取此条记录的时间 
             D - 获取的结果
    """
    start = time.time()
    try:
        D = GetWhoisInfo(domain, whois_srv).get()  # 获取
    except Exception as e:
        D = str(e)
    end = time.time()
    T = end - start
    return T, D
Ejemplo n.º 3
0
def domain_pull(ch, method, properties, body):
    domain_info = json.loads(body)
    global count, count_lock
    if count_lock.acquire():
        count += 1
        if count % RECORD_INTERVAL == 0:
            print str(datetime.datetime.now()).split('.')[1], '完成:', count
            C.updateCount(count)
        count_lock.release()
    whois_server_first = domain_info['whois_srv']
    func_name = domain_info['func_name']
    domain = domain_info['domain']
    exist = domain_info['exist']

    print domain

    flag_error = '0'  # 错误标志
    flag_first_error = '000'  # 一级错误
    flag_sec_error = '000'  # 二级错误
    whois_server_sec = ''  # 二级服务器
    whois_details = ''  # 返回数据

    # 可能存在二级服务器
    if func_name == 'com_manage':
        whois_details_first = ''
        try:
            whois_details_first = GetWhoisInfo(domain,
                                               whois_server_first).get()
            if xxx_bool(whois_details_first):
                whois_details_first = GetWhoisInfo('=' + domain,
                                                   whois_server_first).get()
        except WhoisConnectException as e:
            flag_error = '1'
            flag_first_error = bin(int(str(e)))[2:]
            flag_first_error = '0' * (3 -
                                      len(flag_first_error)) + flag_first_error

        whois_details_sec = None
        try:
            whois_server_sec = get_sec_server(whois_details_first, domain)
            if whois_server_sec:
                whois_details_sec = GetWhoisInfo(domain,
                                                 whois_server_sec).get()
        except WhoisConnectException as e:
            flag_error = '1'
            flag_sec_error = bin(int(str(e)))[2:]
            flag_sec_error = '0' * (3 - len(flag_sec_error)) + flag_sec_error
            whois_details = whois_details_first
        else:
            whois_details = whois_details_sec
    else:
        try:
            whois_details = GetWhoisInfo(domain, whois_server_first).get()
        except WhoisConnectException as e:
            flag_error = '1'
            flag_first_error = bin(int(str(e)))[2:]
            flag_first_error = '0' * (3 -
                                      len(flag_first_error)) + flag_first_error
            flag_sec_error = '000'

    # 测试日志功能
    if MONITOR_FLAG:
        global WhoisDetail_log, log_lock

        if log_lock.acquire():
            WhoisDetail_log.write(whois_details)
            WhoisDetail_log.write('\n')
        log_lock.release()

    print whois_details, "---falg", flag_first_error
    whois_push(
        domain=domain,
        top_whois_server=whois_server_first,
        sec_whois_server=whois_server_sec,
        whois_details=whois_details,
        result_flag='1' + flag_error + flag_first_error +
        flag_sec_error,  # 结果标志
        func_name=func_name,
        exist=exist)
    ch.basic_ack(delivery_tag=method.delivery_tag)  # 返回处理完成确认信息
Ejemplo n.º 4
0
def get_whois(domain_info):
    whois_server_first = domain_info['whois_srv']
    func_name = domain_info['func_name']
    domain = domain_info['domain']
    exist = domain_info['exist']

    flag_error = '0'  # 错误标志
    flag_first_error = '000'  # 一级错误
    flag_sec_error = '000'  # 二级错误
    whois_server_sec = ''  # 二级服务器
    whois_details = ''  # 返回数据

    # 可能存在二级服务器
    if func_name == 'com_manage':
        whois_details_first = ''
        try:
            whois_details_first = GetWhoisInfo(domain,
                                               whois_server_first).get()
            if xxx_bool(whois_details_first):
                whois_details_first = GetWhoisInfo('=' + domain,
                                                   whois_server_first).get()
        except WhoisConnectException as e:
            flag_error = '1'
            flag_first_error = bin(int(str(e)))[2:]
            flag_first_error = '0' * (3 -
                                      len(flag_first_error)) + flag_first_error

        whois_details_sec = None
        try:
            whois_server_sec = get_sec_server(whois_details_first, domain)
            if whois_server_sec:
                whois_details_sec = GetWhoisInfo(domain,
                                                 whois_server_sec).get()
        except WhoisConnectException as e:
            flag_error = '1'
            flag_sec_error = bin(int(str(e)))[2:]
            flag_sec_error = '0' * (3 - len(flag_sec_error)) + flag_sec_error
            whois_details = whois_details_first
        else:
            whois_details = whois_details_sec
    else:
        try:
            whois_details = GetWhoisInfo(domain, whois_server_first).get()
        except WhoisConnectException as e:
            flag_error = '1'
            flag_first_error = bin(int(str(e)))[2:]
            flag_first_error = '0' * (3 -
                                      len(flag_first_error)) + flag_first_error
            flag_sec_error = '000'

    whois_result = {
        'domain': domain,
        'top_whois_server': whois_server_first,
        'sec_whois_server': whois_server_sec,
        'whois_details': whois_details,
        'result_flag':
        '1' + flag_error + flag_first_error + flag_sec_error,  # 结果标志
        'func_name': func_name,
        'exist': exist
    }
    return whois_result