从服务器读取IP并将检测数据写入数据库
This commit is contained in:
@ -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)
|
Reference in New Issue
Block a user