-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSendRemoteCommandsWithAutentication_Italian.py
More file actions
126 lines (104 loc) · 4.38 KB
/
SendRemoteCommandsWithAutentication_Italian.py
File metadata and controls
126 lines (104 loc) · 4.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# Software Name: Send Remote Commands
# Author: Bocaletto Luca
# Site Web: https://www.elektronoide.it
# License: GPLv3
import tkinter as tk
import tkinter.messagebox as messagebox
import socket
# Creazione della finestra principale
window = tk.Tk()
window.title("Invia Comandi Remoti")
# Etichetta per il titolo
title_label = tk.Label(window, text="Invia Comandi Remoti", font=("Helvetica", 16))
title_label.pack()
# Etichette e campi di input per l'indirizzo IP del server, la porta, il nome utente e la password
ip_label = tk.Label(window, text="Indirizzo IP del Server:")
ip_label.pack()
ip_entry = tk.Entry(window)
ip_entry.pack()
port_label = tk.Label(window, text="Porta del Server:")
port_label.pack()
port_entry = tk.Entry(window)
port_entry.pack()
username_label = tk.Label(window, text="Nome Utente:")
username_label.pack()
username_entry = tk.Entry(window)
username_entry.pack()
password_label = tk.Label(window, text="Password:")
password_label.pack()
password_entry = tk.Entry(window, show="*") # Usa 'show' per nascondere la password
password_entry.pack()
# Pulsante per connettersi al server (nella finestra principale)
connect_button = tk.Button(window, text="Connetti al Server")
connect_button.pack()
# Etichetta per lo stato della connessione (nella finestra principale)
status_label = tk.Label(window, text="")
status_label.pack()
# Etichetta e campo di input per inviare comandi (nella finestra principale)
command_label = tk.Label(window, text="Comando:")
command_label.pack()
command_entry = tk.Entry(window)
command_entry.pack()
# Pulsante per inviare comandi (nella finestra principale)
send_button = tk.Button(window, text="Invia Comando")
send_button.pack()
# Etichetta per la risposta del server (nella finestra principale)
response_label = tk.Label(window, text="Risposta del Server:")
response_label.pack()
response_text = tk.Text(window, height=10, width=40)
response_text.pack()
response_text.config(state=tk.DISABLED)
# Inizializzazione del socket client
client_socket = None
# Funzione per connettersi al server remoto con autenticazione
def connect_to_server():
global client_socket
server_ip = ip_entry.get()
server_port_str = port_entry.get()
username = username_entry.get()
password = password_entry.get()
try:
server_port = int(server_port_str)
except ValueError:
messagebox.showerror("Errore", "La porta deve essere un numero intero.")
return
if not server_ip or not server_port_str or not username or not password:
messagebox.showerror("Errore", "Inserisci un indirizzo IP valido, una porta, un nome utente e una password.")
return
try:
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket.connect((server_ip, server_port))
# Invia nome utente e password al server per l'autenticazione
dati_autenticazione = f"{username}:{password}"
client_socket.send(dati_autenticazione.encode())
risposta = client_socket.recv(1024).decode()
if risposta == "Autenticato":
status_label.config(text="Connesso al server")
connect_button.config(state=tk.DISABLED)
else:
status_label.config(text="Autenticazione fallita")
client_socket.close()
except Exception as e:
status_label.config(text=f"Errore di connessione: {str(e)}")
# Pulsante per connettersi al server (nella finestra principale)
connect_button.config(command=connect_to_server)
# Funzione per inviare comandi al server remoto
def send_command():
comando = command_entry.get()
if comando:
try:
client_socket.send(comando.encode())
risposta = client_socket.recv(1024).decode()
response_text.config(state=tk.NORMAL)
response_text.delete(1.0, tk.END) # Cancella il testo esistente
response_text.insert(tk.END, risposta)
response_text.config(state=tk.DISABLED)
except Exception as e:
response_text.config(state=tk.NORMAL)
response_text.delete(1.0, tk.END)
response_text.insert(tk.END, f"Errore: {str(e)}")
response_text.config(state=tk.DISABLED)
# Pulsante per inviare comandi (nella finestra principale)
send_button.config(command=send_command)
# Ciclo GUI principale
window.mainloop()