import socket import os from pynput import mouse, keyboard from pynput.keyboard import Key from pynput.mouse import Button keyboard = keyboard.Controller() mouse = mouse.Controller() #press # device's IP address SERVER_HOST = "0.0.0.0" #(socket.gethostbyname(socket.gethostname())) SERVER_PORT = 5001 # receive 4096 bytes each time BUFFER_SIZE = 128 SEPARATOR = "" # create the server socket # TCP socket s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # bind the socket to our local address s.bind((SERVER_HOST, SERVER_PORT)) # enabling our server to accept connections # 5 here is the number of unaccepted connections that # the system will allow before refusing new connections # s.listen(5) print(f"[*] Listening as {SERVER_HOST}:{SERVER_PORT}") # accept connection if there is any # client_socket, address = s.accept() # if below code is executed, that means the sender is connected # print(f"[+] {address} is connected.") def pressRrelease_char(char, which): if (which == "P"): keyboard.press(char) else: keyboard.release(char) while True: # read 1024 bytes from the socket (receive) bytes_read = s.recv(BUFFER_SIZE) if not bytes_read: # nothing is received # file transmitting is done take another time break ge = bytes_read.decode() MrK = ge[0:1] ge = ge[1:] TrR = ge[0:1] ge = ge[1:] if (MrK == "K"): print (ge) try: if (ge == "Key.enter"): pressRrelease_char(Key.enter, TrR) elif (ge == "Key.shift"): pressRrelease_char(Key.shift, TrR) elif (ge == "Key.space"): pressRrelease_char(Key.space, TrR) elif (ge == "Key.backspace"): pressRrelease_char(Key.backspace, TrR) elif (ge == "Key.ctrl_r"): pressRrelease_char(Key.ctrl_r, TrR) elif (ge == "Key.ctrl_l"): pressRrelease_char(Key.ctrl_l, TrR) elif (ge == "Key.ctrl"): pressRrelease_char(Key.ctrl, TrR) elif (ge == "Key.shift_r"): pressRrelease_char(Key.shift_r, TrR) elif (ge == "Key.alt_l"): pressRrelease_char(Key.alt_l, TrR) elif (ge == "Key.alt_r"): pressRrelease_char(Key.alt_r, TrR) elif (ge == "Key.alt"): pressRrelease_char(Key.alt, TrR) elif (ge == "Key.cmd"): pressRrelease_char(Key.cmd, TrR) elif (ge == "Key.caps_lock"): pressRrelease_char(Key.caps_lock, TrR) elif (ge == "Key.tab"): pressRrelease_char(Key.tab, TrR) elif (ge == "Key.f1"): pressRrelease_char(Key.f1, TrR) elif (ge == "Key.f2"): pressRrelease_char(Key.f2, TrR) elif (ge == "Key.f3"): pressRrelease_char(Key.f3, TrR) elif (ge == "Key.f4"): pressRrelease_char(Key.f4, TrR) elif (ge == "Key.f5"): pressRrelease_char(Key.f5, TrR) elif (ge == "Key.f6"): pressRrelease_char(Key.f6, TrR) elif (ge == "Key.f7"): pressRrelease_char(Key.f7, TrR) elif (ge == "Key.f8"): pressRrelease_char(Key.f8, TrR) elif (ge == "Key.f9"): pressRrelease_char(Key.f9, TrR) elif (ge == "Key.f10"): pressRrelease_char(Key.f10, TrR) elif (ge == "Key.f11"): pressRrelease_char(Key.f11, TrR) elif (ge == "Key.f12"): pressRrelease_char(Key.f12, TrR) elif (ge == "Key.esc"): pressRrelease_char(Key.esc, TrR) elif (ge == "Key.insert"): pressRrelease_char(Key.insert, TrR) elif (ge == "Key.delete"): pressRrelease_char(Key.delete, TrR) elif (ge == "Key.end"): pressRrelease_char(Key.end, TrR) elif (ge == "Key.num_lock"): pressRrelease_char(Key.num_lock, TrR) elif (ge == "Key.home"): pressRrelease_char(Key.home, TrR) elif (ge == "Key.page_up"): pressRrelease_char(Key.page_up, TrR) elif (ge == "Key.page_down"): pressRrelease_char(Key.page_down, TrR) elif (ge == "Key.pause"): pressRrelease_char(Key.pause, TrR) elif (ge == "Key.scroll_lock"): pressRrelease_char(Key.scroll_lock, TrR) elif (ge == "Key.menu"): pressRrelease_char(Key.menu, TrR) elif (ge == "Key.print_screen"): pressRrelease_char(Key.print_screen, TrR) elif (ge == "Key.left"): pressRrelease_char(Key.left, TrR) elif (ge == "Key.up"): pressRrelease_char(Key.up, TrR) elif (ge == "Key.right"): pressRrelease_char(Key.right, TrR) elif (ge == "Key.down"): pressRrelease_char(Key.down, TrR) else: pressRrelease_char((ge), TrR) except: print("an error occured with ", ge) if (MrK == "M"): try: y = int(ge[((int(ge.find(',')+1))):]) x = int(ge[:(int(ge.find(',')))]) print(x) print(y) mouse.position = (x,y) if (TrR == 'R'): mouse.click(Button.right, 1) print (TrR) else: mouse.click(Button.left, 1) print (TrR) except: print ("error") # close the client socket #client_socket.close() # close the server socket #s.close()