Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2019
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. from socket import socket
  2. from threading import Thread
  3. from zlib import compress
  4.  
  5. from mss import mss
  6. import time
  7.  
  8. Width = 1920
  9. Height = 1080
  10.  
  11.  
  12. def screenshot(conn):
  13. with mss() as sct:
  14. rect = {'top': 0, 'left':0, 'width': Width, 'height': Height}
  15.  
  16. while 'recording':
  17. img = sct.grab(rect)
  18.  
  19. pixels = compress(img.rgb, 6)
  20.  
  21. size = len(pixels)
  22. size_len = (size.bit_length() + 7) // 8
  23. sock.sendto(bytes([size_len]))
  24.  
  25. size_bytes = size.to_bytes(size_len, 'big')
  26. sock.sendto(size_bytes)
  27.  
  28. sock.sentto(pixels)
  29. time.sleep(.25)
  30.  
  31. def main(host='127.0.0.1', port=5000):
  32. sock = socket()
  33. sock.bind((host, port))
  34. sock.socket(socket.AF_INET, socket.SOCK_DGRAM)
  35. try:
  36. sock.listen(5)
  37. print('Server Started')
  38. while 'connected':
  39. _, addr = sock.recvfrom()
  40. print('Client connected IP:', addr)
  41. thread = Thread(target=screenshot, args=(addr,))
  42. thread.start()
  43. finally:
  44. pass
  45.  
  46. if __name__ == '__main__':
  47. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement