Ejemplo n.º 1
0
def main(work_type=0):
    """
    主流程
    :param work_type: 工作类型  0:获取全部域名数据
                               1:获取新数据
                              -1: 重新探测失败数据
    """
    # 初始化
    global TaskQueue, ResultQueue
    DB = DataBase()
    DB.db_connect()
    init_sql = """USE {DB}""".format(DB=Static.HTTP_DATEBASE)
    DB.execute_no_return(init_sql)

    # 获取任务域名
    GetDomain(DB, work_type)

    # 开始获取域名解析情况
    thread_list = []
    for i in range(Static.HTTP_PROCESS_NUM):
        get_whois_thread = threading.Thread(target=work)
        get_whois_thread.setDaemon(True)
        get_whois_thread.start()
        thread_list.append(get_whois_thread)

    # 开始域名字典,更新数据库
    sleep(Static.HTTP_TIME_OUT)  # 等待队列填充
    update_whois_thread = threading.Thread(target=UpdateDate(DB))
    update_whois_thread.setDaemon(True)
    update_whois_thread.start()
    thread_list.append(update_whois_thread)

    # 挂起进程直到结束
    for update_whois_thread in thread_list:
        update_whois_thread.join()
    print "域名解析情况获取结束"

    # 清空队列
    while not TaskQueue.empty():
        TaskQueue.get()
    while not ResultQueue.empty():
        ResultQueue.get()
    DB.db_commit()
    DB.db_close()
Ejemplo n.º 2
0
        return 5
    elif domain[0:1] == 'b' or domain[0:1] == 'j' or domain[0:1] == 'o':
        return 6
    elif domain[0:1] == 'p' or domain[0:1] == 'g':
        return 7
    elif domain[0:1] == 'd' or domain[0:1] == 'l' or domain[0:1].isdigit():
        return 8
    elif domain[0:1] == 'f' or domain[0:1] == 'w' or domain[
            0:1] == 'u' or domain[0:1] == 'y' or domain[0:1] == 'z':
        return 9
    elif domain[0:1] == 'e' or domain[0:1] == 'r' or domain[0:1] == 'k':
        return 10
    else:
        return 7


if __name__ == "__main__":
    DB = DataBase()
    SQL = SQL_generate()
    DB.db_connect()
    DB.execute_no_return(
        """USE {database}""".format(database=str(Static.DATABASE_NAME)))
    domain_list = get_domain_file()
    for i in range(len(domain_list)):
        domain = domain_list[i]
        domain_table = 'domain_' + str(domain_divide(domain))
        sql = SQL.GET_DOMAIN_DIVIDE(domain_table, domain)
        DB.execute(sql)
    DB.db_commit()
    DB.db_close()