import asyncio
import websockets
import os,glob
import time
import threading
import win32print
import win32api
import socket
import struct
import tempfile,time
printer_name = win32print.GetDefaultPrinter()
tcp_socket=socket.socket(socket.AF_INET,socket.SOCK_STREAM) #
try:
tcp_socket.json()
except:
tcp_socket.connect(("10.1.1.225",3000))
else:
raise ValueError
from pynput.keyboard import Key, Controller as c_keyboard
from pynput.mouse import Button, Controller as c_mouse
keyboard = c_keyboard()
from threading import Thread
def keyboardjing(num,tim,hek):
months = {1: "1",2: "2",3: "3", 4: "4",5: "5",6: "6",7: "7",8: "8",9: "9",0: "0"}
monthstext= months.get(num, "Invalid num")
keyboard.press(Key.alt)
keyboard.press(monthstext)
time.sleep(0.01)
keyboard.release(Key.alt)
keyboard.release(monthstext)
monthsB = {1: "a",2: "b",3: "c", 4: "d",5: "e",6: "f",6: "g",7: "h",8: "i",9: "j",0: "k"}
monthstB= monthsB.get(num, "Invalid num")
Thread(target=keyboardjingspeel(monthstB,tim),name=hek).start()
def keyboardjingspeel(monthstext,tim):
time.sleep(tim)
keyboard.press(Key.alt)
keyboard.press(monthstext)
time.sleep(0.01)
keyboard.release(Key.alt)
keyboard.release(monthstext)
def tcpsand(hex7,hex31,hex6):#hex7k,hex3 12=18开 11=17关 25=37定时,hex6#时间
#hexop7=1#开关
hex1 = 85
hex2 = 1
if hex31==1 :hex3=18
elif hex31==2 :hex3=17
else :hex3=37
#hex3=int('0x25',16) #12 16HEX=18开 11 16HEX=17关 25=37定时,
#hex31=int('0x11',16)
hex4=int('0x00',16) #45位
hex5=int('0x00',16) #45位
#hex6=3 # #int('0x05',16) #时
if hex6<0 :hex6=0
#hex7='%s%s'%('0x', hexop7)
#hex7=8 路和
hex8=hex1+hex2+hex3+hex4+hex5+hex6+hex7
send_data=[hex1,hex2,hex3,hex4,hex5,hex6,hex7,hex8]
#send_data = [0x55,0x1,0x12,0x00,0x00,0x00,0x06,0x6e]#input("请输入要传输的数据:")
#print(send_data)
data = struct.pack("%dB" % (len(send_data)), *send_data)
##""" """print (data)
tcp_socket.send(data)
def dlinkprint(filstext):
filename = tempfile.mktemp('.txt')
file = open(filename , 'w', encoding='utf-8')
file.write (filstext)
win32api.ShellExecute(0,"print",filename,'/d:"%s"' % printer_name,".",0)
def gotodo6(ans):#送粉丝团
if ans.find('送粉丝团灯牌')!=-1:
t92=Thread(target=tcpsand(8,3,5),name=ans+'tcpsand')#8路3定时5秒
t92.start()
elif ans.find('送小心心')!=-1:
t92=Thread(target=tcpsand(8,3,5),name=ans+'tcpsand')#8路3定时5秒
t92.start()
elif ans.find('送人气票')!=-1:
t92=Thread(target=tcpsand(8,3,5),name=ans+'tcpsand')#8路3定时5秒
t92.start()
elif ans.find('送玫瑰')!=-1:
t92=Thread(target=tcpsand(8,3,5),name=ans+'tcpsand')#8路3定时5秒
t92.start()
elif ans.find('送梦幻热气球')!=-1:
t92=Thread(target=tcpsand(8,3,5),name=ans+'tcpsand')#8路3定时5秒
t92.start()
elif ans.find('送梦幻热气球')!=-1:
t92=Thread(target=tcpsand(8,3,5),name=ans+'tcpsand')#8路3定时5秒
t92.start()
elif ans.find('送大啤酒')!=-1:
t92=Thread(target=tcpsand(8,3,5),name=ans+'tcpsand')#8路3定时5秒
t92.start()
elif ans.find('送保时捷')!=-1:
t92=Thread(target=tcpsand(8,3,5),name=ans+'tcpsand')#8路3定时5秒
t92.start()
elif ans.find('抖音1号')!=-1:
t92=Thread(target=tcpsand(8,3,5),name=ans+'tcpsand')#8路3定时5秒
t92.start()
else:
t102=Thread(target=tcpsand(8,3,5),name=ans+'tcpsand')#8路3定时5秒
t102.start()
IP_ADDR = "10.1.1.123"
IP_PORT = "8765"
import datetime
from pynput.keyboard import Key, Controller as c_keyboard
from pynput.mouse import Button, Controller as c_mouse
folder_path ='E:\FTP'
tmptext=open('pin4.py', 'r' ,encoding="utf-8").read()
tmpGans=open('ipmod.py', 'r' ,encoding="utf-8").read()
folder_path ='E:\FTP'
if os.path.exists(folder_path):
for file in glob.glob(folder_path+'\*'):
os.remove(file)
#os.rmdir(folder_path)
else:
# file not found message
print("File not found in the directory")
os.mkdir(folder_path)
# 握手,通过接收hello,发送"123"来进行双方的握手。
async def serverHands(websocket):
while True:
recv_text = await websocket.recv()
if recv_text.find('|')!=-1:
Gans1=recv_text.split('|')[0]
Gans2=recv_text.split('|')[1]
print(Gans1)
if int(Gans2)==6:
Gans1file=folder_path+"/"+str(datetime.datetime.now(tz=None).timestamp()).replace('.','')
open(Gans1file+'.txt', 'w' ,
encoding="utf-8").write(Gans1)
Gans26=Thread(target=gotodo6(Gans1),name=Gans2+'gotodo6')
Gans26.start()
#print("recv_text=" + recv_text)
if recv_text == "hello":
print("connected success")
await websocket.send("123")
return True
#else:
# await websocket.send("connected fail")
# 接收从客户端发来的消息并处理,再返给客户端ok
async def serverRecv(websocket):
while True:
recv_text = await websocket.recv()
print("recv:", recv_text)
await websocket.send("ok!!!")
# 握手并且接收数据
async def serverRun(websocket, path):
print(path)
await serverHands(websocket)
await serverRecv(websocket)
#main function
if __name__ == '__main__':
print("======server main begin======")
server = websockets.serve(serverRun, IP_ADDR, IP_PORT)
asyncio.get_event_loop().run_until_complete(server)
asyncio.get_event_loop().run_forever()
该博客介绍了一个使用websocket实现的系统,通过手机接收指令来模拟抖音直播中的互动行为,如送礼物。系统包括键盘和鼠标模拟、TCP连接到特定IP发送数据以及根据接收到的指令执行相应操作等功能。

4795

被折叠的 条评论
为什么被折叠?



