From 919fc8b839062ccafbda17d3142d019fa65cc32e Mon Sep 17 00:00:00 2001 From: xyj Date: Sat, 9 Mar 2024 14:28:24 +0800 Subject: [PATCH] first --- .idea/.gitignore | 3 + .../inspectionProfiles/profiles_settings.xml | 6 ++ .idea/misc.xml | 7 +++ .idea/modules.xml | 8 +++ .idea/pythonProject.iml | 10 +++ click.py | 36 +++++++++++ main.py | 62 +++++++++++++++++++ test.py | 0 8 files changed, 132 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/pythonProject.iml create mode 100644 click.py create mode 100644 main.py create mode 100644 test.py diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..1e51326 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..e15ec35 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/pythonProject.iml b/.idea/pythonProject.iml new file mode 100644 index 0000000..2c80e12 --- /dev/null +++ b/.idea/pythonProject.iml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/click.py b/click.py new file mode 100644 index 0000000..cbcceca --- /dev/null +++ b/click.py @@ -0,0 +1,36 @@ +import pyautogui + +a = { + "Type": 1, + "Index": 0, + "DataNum": 1, + "PointNum": 4, + "Check": 38, + "Point": [ + { + "x": 100, + "y": 100 + }, + { + "x": 100, + "y": 100 + }, + { + "x": 100, + "y": 100 + }, + { + "x": 100, + "y": 100 + } + ] +} + + +def click_it(x, y): + pyautogui.moveTo(x, y) + pyautogui.click(x, y) + + +if __name__ == '__main__': + click_it(100, 100) \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..9fc14ad --- /dev/null +++ b/main.py @@ -0,0 +1,62 @@ +# coding=utf-8 +# 多线程TCP服务器 +import json + +import pyautogui +import socket +import threading + + +def click_it(x, y): + pyautogui.moveTo(x, y) + pyautogui.click(x, y) + + +bind_ip = "127.0.0.1" # 监听的IP 地址 +bind_port = 9999 # 监听的端口 + +# 建立一个socket对象 +server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + +# 绑定监听的地址,创建的对象是AF_INET的形式,所以地址(ip, port)的元组形式来表示 +server.bind((bind_ip, bind_port)) + +# 启动监听并设置连接数为5 +server.listen(5) + +print("[*] Listening on %s:%d" % (bind_ip, bind_port)) + + +# 这是客户处理线程,也是一个回调函数,创建一个新的进程对象,将客户端套接字对象作为一个句柄传递给它。 +def handle_client(client_socket): + # 打印处客户端发送得到的内容 + data = client_socket.recv(1024) + try: + data = data.decode("utf-8") + Point = json.loads(data)["Point"] + print(Point[0]) + + except Exception as e: + print(e) + # 返还一个 ACK 在计算机网络中的意思是返回包确认,表示收到 + client_socket.send(b"ACK!") + client_socket.close() + + +# 等待连接,这里必定进入循环 +while True: + # 一个客户端成功建立连接的时候,我们将收到的客户端套接字对象保存到client变量中,将远程连接的细节保存到addr变量中。 + # 返回的client是一个套接字,是表示专属客户的一个新的套接字 | 而addr则是一个tuple元组,抓了某次数据返回的就是('127.0.0.1', 62549) + # 运行到下面就被当作套接字传递给上面自定义的 handle_client 函数 + client, addr = server.accept() + + # 打印结果 在('127.0.0.1', 62549)中addr[0] -> 127.0.0.1,addr[1] -> 62549 + print("[*] Accepted connection from: %s:%d" % (addr[0], addr[1])) + + # 挂起客户端线程,处理传入的数据。 + # Thread是一个类,创建一个新的线程对象,target指定调用的函数,args指定调用函数的参数,是一个元组,后面要加一个’,’ + # 当调用start函数时,就回去执行这个函数 + client_handler = threading.Thread(target=handle_client, args=(client,)) + + # 启动线程开始处理客户端连接。handle_client 函数执行recv()函数之后将一段信息发送给客户端 + client_handler.start() diff --git a/test.py b/test.py new file mode 100644 index 0000000..e69de29