def update_db(): """ 更新数据库 """ svr_num = sum_all_list() db = MySQL(DESTINATION_CONFIG) db.truncate('TRUNCATE TABLE top_sec_svr') sql = 'INSERT INTO top_sec_svr(top_svr, sec_svr, whois_sum) VALUES("%s", "%s", "%s")' for top,sec,num in svr_num: db.insert_no_commit(sql % (top,sec,num)) db.commit() db.close()
def test(results): db = MySQL() for url_feature in results: print url_feature sql = 'UPDATE url_features SET url_length = "%s", domain="%s",domain_tokens="%s",domain_characters="%s",path="%s", ' \ 'path_tokens="%s",path_characters="%s",path_brand="%s" WHERE url="%s"' % \ (url_feature[1],url_feature[2],url_feature[3],url_feature[4],url_feature[5],url_feature[6], url_feature[7],url_feature[8],url_feature[0]) db.no_update(sql) db.commit() db.close()
def update_db(): """更新数据库""" tld_num = sum_all_domains() db = MySQL(DESTINATION_CONFIG) db.truncate('TRUNCATE TABLE domain_summary') update_sql = 'INSERT INTO domain_update(tld_name, domain_num) VALUES("%s", "%s")' summary_sql = 'INSERT INTO domain_summary(tld_name, domain_num) VALUES("%s", "%s")' for tld,num in tld_num: db.insert_no_commit(update_sql % (tld,num)) db.insert_no_commit(summary_sql % (tld,num)) db.commit() db.close()
def insert_db(): url_set = pd.read_csv('csv/kt-content.csv') db = MySQL() for i in range(len(url_set)): print url_set.ix[i].values sql = 'Insert ignore into benign_urls(url,type)VALUES ("%s","%s")' % ( url_set.ix[i].values[1], url_set.ix[i].values[2]) db.insert_no_commit(sql) db.commit() db.close()
def update_destination(tb_name, results): """ 更新数据库 :param results: :return: """ destination_db = MySQL(DESTINATION_CONFIG) destination_db.truncate('TRUNCATE TABLE domain_whois_%s' % tb_name) for item in results: destination_db.insert_no_commit('INSERT INTO domain_whois_%s (tld,flag,whois_sum) VALUES ("%s","%s","%s")' % ( tb_name, item[0], item[1], item[2])) destination_db.commit() destination_db.close()
def update_db(): """更新数据库""" tld_whois = sum_all_whois() total = 0 db = MySQL(DESTINATION_CONFIG) sql = 'INSERT INTO tld_whois_sum_history(tld,whois_sum) VALUES("%s", "%s")' # 插入数据 for tld, whois in tld_whois: db.insert_no_commit(sql % (tld, whois)) total += whois db.commit() sql = 'INSERT INTO whois_sum(tld_sum) VALUES("%s")' db.insert(sql % total) db.close()
def insert_db(): file_name = open('small_benign.txt') urls = file_name.readlines() db = MySQL() count = 0 for url in urls: sql = 'Insert into url_features(url,malicious)VALUES ("%s","0")'%(url.strip()) db.insert_no_commit(sql) count += 1 db.commit() db.close() print count
def update_db(): """更新数据库""" tld_whois = sum_all_whois() total = 0 db = MySQL(DESTINATION_CONFIG) sql = 'INSERT INTO tld_whois_sum_history(tld,whois_sum) VALUES("%s", "%s")' # 插入数据 for tld,whois in tld_whois: db.insert_no_commit(sql % (tld,whois)) total += whois db.commit() sql = 'INSERT INTO whois_sum(tld_sum) VALUES("%s")' db.insert(sql % total) db.close()
def insert_domains(domain_set): """ 更新数据库中词汇特征 :param url_feature: :return: """ db = MySQL() for domain in domain_set: sql = 'Insert into domain_features(domain,tld,tld_token_count,domain_length,domain_characters,domain_digit)VALUES ("%s","%s","%s","%s","%s","%s")' \ %(domain['domain'],domain['tld'],domain['tld_token_count'],domain['domain_length'],domain['character'],domain['digit']) db.insert_no_commit(sql) db.commit() db.close()
def insert_db(): file_name = open('small_benign.txt') urls = file_name.readlines() db = MySQL() count = 0 for url in urls: sql = 'Insert into url_features(url,malicious)VALUES ("%s","0")' % ( url.strip()) db.insert_no_commit(sql) count += 1 db.commit() db.close() print count
def update_db(): """更新数据库""" db = MySQL(DESTINATION_CONFIG) truncate_sql = 'TRUNCATE TABLE tld_whois_flag' db.truncate(truncate_sql) sql = 'INSERT INTO tld_whois_flag(tld, flag,flag_detail, whois_sum) VALUES("%s", "%s", "%s", "%s")' tld_flag_num = sum_all_flags() for tld, flag_detail, num in tld_flag_num: try: if int(flag_detail) < 0: flag = '0' elif int(flag_detail) >= 120: flag = '1' elif flag_detail == '102' or flag_detail == '110' or flag_detail == '112': flag = '2' else: flag = '3' db.insert_no_commit(sql % (tld,flag,flag_detail,num)) except: continue db.commit() db.close()