finish and reorganise

This commit is contained in:
Daniel
2021-03-23 10:05:04 +00:00
parent ba47435068
commit 8338243950
10 changed files with 51 additions and 4 deletions

View File

@ -0,0 +1,96 @@
import socket
import os
from pynput import keyboard
SEPARATOR = "<SEPARATOR>"
BUFFER_SIZE = 128 # send 4096 bytes each time step
# the ip address or hostname of the server, the receiver
host = "127.0.0.1"
# the port, let's use 5001
port = 5001
# the name of file we want to send, make sure it exists
filename = "data.txt"
# get the file size
filesize = os.path.getsize("data.txt")
# create the client socket
s = socket.socket()
print(f"[+] Connecting to {host}:{port}")
s.connect((host, port))
print("[+] Connected.")
# send the filename and filesize
s.send(f"{filename}{SEPARATOR}{filesize}".encode())
def sendfile():
# start sending the file
with open(filename, "rb") as f:
while True:
# read the bytes from the file
bytes_read = f.read(BUFFER_SIZE)
if not bytes_read:
# file transmitting is done
break
# we use sendall to assure transimission in
# busy networks
s.sendall(bytes_read)
# close the socket
#s.close()
#-----------------------------------------------------------
def on_press(key):
if str(key) == 'Key.enter':
text_file = open("data.txt", "w")
text_file.write("\n")
text_file.close()
sendfile()
elif str(key) == 'Key.space':
text_file = open("data.txt", "w")
text_file.write(" ")
text_file.close()
sendfile()
elif str(key) == 'Key.backspace':
print("Invalid")
else:
text_file = open("data.txt", "w")
text_file.write(('{}'.format(key)).replace("'", ""))
text_file.close()
sendfile()
def on_release(key):
#print('Key {} released.'.format(key))
if str(key) == 'Key.esc':
print('Exiting...')
return False
with keyboard.Listener(
on_press = on_press,
on_release = on_release) as listener:
listener.join()
#-----------------------------------------

View File

@ -0,0 +1,73 @@
import socket
import os
from multiprocessing import Process
from tkinter import *
from pynput import keyboard
from pynput.mouse import Button, Controller
from pynput import mouse
# ipFile = open("IP.txt")
# IP = ipFile.read()
# ipFile.close()
import threading # https://docs.python.org/3/library/threading.html
import queue #
# window = Tk()
# label = Label(window, text= 'What is the IP')
# entry = Entry(window, width=200)
# entry.insert(END, IP)
# label.pack()
# entry.pack()
MOUSE = Controller()
dataToSend = ""
SEPARATOR = "<SEPARATOR>"
BUFFER_SIZE = 128 # send 4096 bytes each time step
host = "safe-mask.auto.playit.gg"
# the ip address or hostname of the server, the receiver
# the port, let's use 5001
port = 56926
# create the client socket
s = socket.socket()
print(f"[+] Connecting to {host}:{port}")
s.connect((host, port))
print("[+] Connected.")
# -----------------------------------------------------------
def on_press(key):
dataToSend = "KP"
dataToSend = dataToSend + (('{}'.format(key)).replace("'", ""))
dataToSendBytes = dataToSend.encode()
s.sendall(dataToSendBytes)
def on_release(key):
dataToSend = "KR"
dataToSend = dataToSend + (('{}'.format(key)).replace("'", ""))
dataToSendBytes = dataToSend.encode()
s.sendall(dataToSendBytes)
def on_click(x, y, button, pressed):
if button == Button.left:
dataToSend = ("ML")
else:
dataToSend = ("MR")
dataToSend = dataToSend + str(x) + "," + str(y)
dataToSendBytes = dataToSend.encode()
s.sendall(dataToSendBytes)
def mouseThread():
with mouse.Listener(on_click=on_click) as mouseListener:
mouseListener.join()
threading.Thread(target=mouseThread).start()
with keyboard.Listener(on_press=on_press, on_release=on_release) as keyListener:
keyListener.join()

View File

@ -0,0 +1,61 @@
import socket
import os
#from test import update_image
# device's IP address
SERVER_HOST = "0.0.0.0" #(socket.gethostbyname(socket.gethostname()))
SERVER_PORT = 5001
# receive 4096 bytes each time
BUFFER_SIZE = 4096
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:
# 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
try:
hello = bytes_read.decode()
#update_image()
os.remove("screen.jpg")
os.rename(r"screen_download.jpg",r"screen.jpg")
print("I am moving the file")
except:
f = open("screen_download.jpg", 'ab')
f.write(bytes_read)
print("I am adding to the file")
f.close()
# close the client socket
#client_socket.close()
# close the server socket
#s.close()

View File

@ -0,0 +1,44 @@
#!/usr/bin/python3
#Displays a loop of all image files found by gather_files.py. Run that script first to populate your image db file. See README for python dependency installation hints.
import tkinter as tk
from PIL import ImageTk, Image
import os, random, time
#Loop through a new image every 4 seconds.
def update_image():
path = "screen.jpg"
try:
img = ImageTk.PhotoImage(Image.open(path).resize((800, 480)))
#Issue with image file, try another.
except Exception as e:
print("Error: " + str(e))
path = get_random_file()
img = ImageTk.PhotoImage(Image.open(path).resize((800, 480)))
panel.configure(image=img)
panel.image = img
window.after(100, update_image)
return
path = "screen.jpg"
window = tk.Tk()
#window.attributes("-fullscreen",True)
window.title("Photo Gallery")
window.geometry("800x480")
window.configure(background='black')
#Load an initial image onto the Label.
try:
img = ImageTk.PhotoImage(Image.open(path).resize((800, 480)))
#Issue with image file, try another.
except Exception as e:
print("Error: " + str(e))
path = "screen.jpg"
img = ImageTk.PhotoImage(Image.open(path).resize((800, 480)))
panel = tk.Label(window, image=img)
panel.pack(side="bottom", fill="both", expand="yes")
update_image()
window.mainloop()

BIN
Controller/screen.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB