2020-12-09 11:52:04 +00:00
|
|
|
import socket
|
|
|
|
import os
|
|
|
|
import pynput
|
|
|
|
from pynput.mouse import Button, Controller
|
|
|
|
import time
|
|
|
|
|
|
|
|
|
|
|
|
mouse=Controller()
|
|
|
|
|
|
|
|
# device's IP address
|
2020-12-10 07:58:48 +00:00
|
|
|
SERVER_HOST = "127.0.0.1" #(socket.gethostbyname(socket.gethostname()))
|
2020-12-09 11:52:04 +00:00
|
|
|
SERVER_PORT = 10002
|
|
|
|
# receive 4096 bytes each time
|
|
|
|
BUFFER_SIZE = 128
|
|
|
|
SEPARATOR = "<SEPARATOR>"
|
|
|
|
# create the server socket
|
|
|
|
# TCP socket
|
|
|
|
s = socket.socket()
|
|
|
|
# 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.")
|
|
|
|
# receive the file infos
|
|
|
|
# receive using client socket, not server socket
|
|
|
|
received = client_socket.recv(BUFFER_SIZE).decode()
|
|
|
|
filename, filesize = received.split(SEPARATOR)
|
|
|
|
# remove absolute path if there is
|
|
|
|
filename = os.path.basename(filename)
|
|
|
|
# convert to integer
|
|
|
|
filesize = int(filesize)
|
|
|
|
# start receiving the file from the socket
|
|
|
|
# and writing to the file stream
|
|
|
|
#with open(filename, "wb") as f:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while True:
|
2020-12-10 08:45:54 +00:00
|
|
|
# read 1024 bytes from the socket (receive)
|
|
|
|
bytes_read = client_socket.recv(BUFFER_SIZE)
|
|
|
|
if not bytes_read:
|
|
|
|
# nothing is received
|
|
|
|
# file transmitting is done take another time
|
|
|
|
break
|
|
|
|
# write to the file the bytes we just received
|
2020-12-09 11:52:04 +00:00
|
|
|
|
2020-12-10 08:45:54 +00:00
|
|
|
# update the progress bar
|
|
|
|
f = open(filename, 'wb')
|
|
|
|
f.write(bytes_read)
|
|
|
|
f.close()
|
2020-12-09 11:52:04 +00:00
|
|
|
|
2020-12-10 08:45:54 +00:00
|
|
|
g = open(filename, 'r')
|
|
|
|
ge = g.read()
|
|
|
|
print (ge)
|
|
|
|
|
|
|
|
TrR = ge[0:1]
|
|
|
|
ge = ge[1:]
|
|
|
|
|
|
|
|
try:
|
|
|
|
y = int(ge[((int(ge.find(',')+1))):])
|
|
|
|
x = int(ge[:(int(ge.find(',')))])
|
2020-12-09 11:52:04 +00:00
|
|
|
|
|
|
|
|
2020-12-10 08:45:54 +00:00
|
|
|
print(x)
|
|
|
|
print(y)
|
|
|
|
mouse.position = (x,y)
|
|
|
|
if (TrR == 'R'):
|
|
|
|
mouse.click(Button.right, 1)
|
|
|
|
print (TrR)
|
2020-12-09 13:09:03 +00:00
|
|
|
|
2020-12-10 08:45:54 +00:00
|
|
|
else:
|
|
|
|
mouse.click(Button.left, 1)
|
|
|
|
print (TrR)
|
2020-12-09 13:09:03 +00:00
|
|
|
|
2020-12-09 11:52:04 +00:00
|
|
|
|
2020-12-10 08:45:54 +00:00
|
|
|
except:
|
|
|
|
print ("error")
|
|
|
|
|
|
|
|
g.close()
|
2020-12-09 11:52:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# close the client socket
|
|
|
|
#client_socket.close()
|
|
|
|
# close the server socket
|
|
|
|
#s.close()
|