资讯动态

holehe数据持久化:将检测历史记录保存到数据库的实现

发布时间:2026/8/14 9:59:45 来源:尧图企业网站定制
holehe数据持久化将检测历史记录保存到数据库的实现【免费下载链接】holeheholehe allows you to check if the mail is used on different sites like twitter, instagram and will retrieve information on sites with the forgotten password function.项目地址: https://gitcode.com/GitHub_Trending/ho/holehe引言在使用holehe进行邮箱检测时用户常常需要保存检测历史记录以便后续分析和查询。然而目前holehe仅支持将结果导出为CSV文件这种方式在数据量大、查询频繁的场景下存在诸多不便。本文将详细介绍如何将holehe的检测历史记录持久化到数据库中以提高数据管理的效率和灵活性。现状分析当前数据处理方式目前holehe通过export_csv函数将检测结果保存到CSV文件中。该函数位于holehe/core.py文件中代码如下def export_csv(data,args,email): Export result to csv if args.csvoutput True: now datetime.now() timestamp datetime.timestamp(now) name_fileholehe_str(round(timestamp))_email_results.csv with open(name_file, w, encodingutf8, newline) as output_file: fc csv.DictWriter(output_file,fieldnamesdata[0].keys()) fc.writeheader() fc.writerows(data) exit(All results have been exported to name_file)存在的问题数据分散每次检测生成一个CSV文件随着检测次数增加文件数量会急剧增多不便于管理。查询困难要查询特定邮箱的检测记录需要遍历所有CSV文件效率低下。数据共享不便CSV文件难以实现多用户共享和实时访问。数据库设计数据库选择考虑到holehe是一个Python项目我们选择SQLite作为数据库因为它轻量级、无需额外配置且Python内置了SQLite3模块便于集成。数据表设计我们设计一个名为detection_history的表来存储检测记录表结构如下字段名类型说明idINTEGER主键自增emailTEXT被检测的邮箱地址domainTEXT检测的网站域名existsBOOLEAN邮箱是否存在rate_limitBOOLEAN是否触发速率限制errorBOOLEAN是否发生错误email_recoveryTEXT邮箱恢复信息phone_numberTEXT电话号码othersTEXT其他信息JSON格式detection_timeDATETIME检测时间实现步骤1. 创建数据库连接模块在holehe目录下创建holehe/database.py文件实现数据库连接和初始化功能import sqlite3 import os from datetime import datetime class Database: def __init__(self, db_nameholehe_history.db): self.db_name db_name self.conn None self.cursor None self.connect() self.init_table() def connect(self): 连接到SQLite数据库 try: self.conn sqlite3.connect(self.db_name) self.cursor self.conn.cursor() except sqlite3.Error as e: print(f数据库连接错误: {e}) def init_table(self): 初始化数据表 create_table_sql CREATE TABLE IF NOT EXISTS detection_history ( id INTEGER PRIMARY KEY AUTOINCREMENT, email TEXT NOT NULL, domain TEXT NOT NULL, exists BOOLEAN, rate_limit BOOLEAN, error BOOLEAN, email_recovery TEXT, phone_number TEXT, others TEXT, detection_time DATETIME NOT NULL ) self.cursor.execute(create_table_sql) self.conn.commit() def insert_record(self, record): 插入检测记录 insert_sql INSERT INTO detection_history ( email, domain, exists, rate_limit, error, email_recovery, phone_number, others, detection_time ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) detection_time datetime.now().strftime(%Y-%m-%d %H:%M:%S) others json.dumps(record.get(others)) if record.get(others) else None self.cursor.execute(insert_sql, ( record[email], record[domain], record[exists], record.get(rateLimit, False), error in record and record[error], record.get(emailrecovery), record.get(phoneNumber), others, detection_time )) self.conn.commit() def close(self): 关闭数据库连接 if self.conn: self.conn.close()2. 修改检测结果处理逻辑修改holehe/core.py中的maincore函数在检测完成后将结果保存到数据库async def maincore(): # ... 现有代码 ... # 关闭客户端 await client.aclose() # 打印结果 print_result(out,args,email,start_time,websites) credit() # 导出结果到CSV export_csv(out,args,email) # 新增保存结果到数据库 from holehe.database import Database db Database() for record in out: # 添加email字段 record[email] email db.insert_record(record) db.close()3. 修改模块输出格式以holehe/modules/mails/google.py和holehe/modules/social_media/twitter.py为例确保所有模块输出的结果包含统一的字段# google.py示例 out.append({ name: name, domain: domain, method: method, frequent_rate_limit: frequent_rate_limit, rateLimit: False, exists: True, emailrecovery: None, phoneNumber: None, others: None }) # twitter.py示例 out.append({ name: name, domain: domain, method: method, frequent_rate_limit: frequent_rate_limit, rateLimit: False, exists: True, emailrecovery: None, phoneNumber: None, others: None })实现效果数据流向查询示例通过以下Python代码可以轻松查询特定邮箱的检测记录import sqlite3 def query_email_history(email): conn sqlite3.connect(holehe_history.db) cursor conn.cursor() cursor.execute(SELECT * FROM detection_history WHERE email ?, (email,)) records cursor.fetchall() conn.close() return records # 使用示例 history query_email_history(testexample.com) for record in history: print(record)总结与展望通过以上步骤我们成功实现了将holehe的检测历史记录保存到SQLite数据库的功能。这一改进解决了CSV文件管理不便的问题提高了数据查询和共享的效率。未来可以进一步扩展以下功能添加用户认证机制实现多用户数据隔离。开发Web界面提供更友好的查询和管理方式。实现数据备份和同步功能提高数据安全性。添加数据统计和分析功能提供检测结果的可视化展示。这些改进将使holehe在数据管理方面更加完善满足更多用户场景的需求。【免费下载链接】holeheholehe allows you to check if the mail is used on different sites like twitter, instagram and will retrieve information on sites with the forgotten password function.项目地址: https://gitcode.com/GitHub_Trending/ho/holehe创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

读完文章,也想定制专属网站?

尧图设计师 24 小时内与您沟通定制方案

免费获取报价