summaryrefslogtreecommitdiff
path: root/server/apps/target.py
diff options
context:
space:
mode:
authorhandingkang <[email protected]>2024-05-23 22:46:11 +0800
committerhandingkang <[email protected]>2024-05-23 22:46:11 +0800
commit37e920d5edc7e782a10d397b9e5dd15429278317 (patch)
tree8502d50fd8837dc430ed80924bb24c08ebc2b8f4 /server/apps/target.py
parent50b34fb103d476c0f20d5ae0069c9eab49ca96bb (diff)
1. 在settings.py中新增RUN_DEV选项,模拟代理运行正常的情况
2. 修复/task/create接口存在问题 3. 更新/target/delay接口
Diffstat (limited to 'server/apps/target.py')
-rw-r--r--server/apps/target.py43
1 files changed, 32 insertions, 11 deletions
diff --git a/server/apps/target.py b/server/apps/target.py
index 154e9d7..600e08a 100644
--- a/server/apps/target.py
+++ b/server/apps/target.py
@@ -6,6 +6,7 @@ import threading
import requests
from apiflask import APIBlueprint, Schema
from apiflask.fields import Integer, String, List, Nested, IP, DateTime, Dict
+from apiflask.validators import OneOf
from requests.exceptions import Timeout
from settings import *
@@ -99,24 +100,44 @@ def get_nodes(query_data):
return {"code": 200, "nodes": node_list}
[email protected]("/delay/<string:type>")
@bp.doc("获取每个节点的时延数据", "type参数为{icmp,dns,tcp}中的一个")
[email protected]({"ip": IP(required=False)}, location="query")
+ "ip": IP(required=True),
+ "taskid": String(required=True),
+ "type": String(required=True, validate=OneOf(['icmp', 'dns', 'tcp']))}, location="query")
@bp.output(DelayOut)
-def get_pernode_delay(query_data, scan_type):
- # TODO:节点选择
- addr = ""
- if 'ip' in query_data.keys():
- addr = query_data['ip']
+# TODO:和实际节点联调测试
+def get_pernode_delay(query_data):
+ # TODO:DoH处理
+ # 探测地址
+ addr = query_data['ip']
+ taskid = query_data['taskid']
+ scan_type = query_data['type']
+
+ # 响应数据
ans = []
- # threads = []
- # df = pd.read_csv("./server.csv", encoding="utf-8")
- # for index, row in df.iterrows():
- # mythread = threading.Thread(target=task, args=[ans, addr, row, type])
+ # 线程池
+ threads = []
+ # # 检索探测节点信息
+ # sql = """
+ # SELECT SCAN_AGENT_ID_LIST as node_info
+ # FROM %s
+ # WHERE TASK_ID='%s'
+ # """ % (MYSQL_TAB_TASK, taskid)
+ # da.cursor.execute(sql)
+ # # 探测节点ID与地址
+ # nodes = json.loads(da.cursor.fetchall()[0]["node_info"].replace('"', "\""))
+ #
+ # for id, ip in nodes.items():
+ # mythread = threading.Thread(target=task, args=[ans, addr, {'id': id, 'ip': ip}, type])
# mythread.start()
# threads.append(mythread)
# for t in threads:
# t.join()
+
+ # 暂未部署实际代理节点,以假数据返回
+ ans = []
for i in range(10):
ans.append({"Id": str(i), "Type": scan_type, "CurrDelay": random.randint(1, 1000)})
return {"code": 200, 'delay_data': ans}