从服务器读取IP并将检测数据写入数据库

This commit is contained in:
2025-09-10 08:57:56 +08:00
parent d3c4820b73
commit ae177ca14a
4 changed files with 200 additions and 83 deletions

View File

@ -236,3 +236,29 @@ async def get_device_list(
raise Exception(f"获取设备列表失败: {str(e)}") from e
finally:
db.close_connection(conn, cursor)
def get_unique_client_ips() -> list[str]:
"""
获取所有去重的客户端IP列表
:return: 去重后的客户端IP字符串列表如果没有数据则返回空列表
"""
conn = None
cursor = None
try:
conn = db.get_connection()
cursor = conn.cursor(dictionary=True)
# 查询去重的客户端IP
query = "SELECT DISTINCT client_ip FROM devices WHERE client_ip IS NOT NULL"
cursor.execute(query)
# 提取结果并转换为字符串列表
results = cursor.fetchall()
return [item['client_ip'] for item in results]
except MySQLError as e:
raise Exception(f"获取客户端IP列表失败: {str(e)}") from e
finally:
db.close_connection(conn, cursor)