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
| from socket import socket, AF_INET, SOCK_STREAM, SOL_SOCKET, SO_REUSEADDR
import threading
from tkinter import *
def Etat_0():
Etat_reseau.set("Bon")
info_etat.config(text="Etat du reseau: Aucun probleme connue")
print("Update", Etat_reseau.get())
def Etat_1():
Etat_reseau.set("Moyen")
info_etat.config(text="Etat du reseau: Presence de ralentissement sur le reseau")
print("Update", Etat_reseau.get())
def Etat_2():
Etat_reseau.set("Mauvais")
info_etat.config(text="Etat du reseau: Reseau indisponible")
print("Update", Etat_reseau.get())
def Serveur():
global Etat_Client
SocketClient = socket(AF_INET, SOCK_STREAM)
SocketClient.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
SocketClient.bind(("",50000))
SocketClient.listen(10)
print("Ecoute...")
Etat_Client = Etat_reseau.get()
while True: #Connecte les clients et leur indique l'etat reseau
(cs, (ip, port)) = SocketClient.accept()
if ip not in Client_online:
print("[+] Nouveau client %s %s" % (ip, port))
nv_client = True
Client_online[ip] = port
cs.send(str(Etat_reseau.get()).encode())
if nv_client == True:
print("Ecoute")
nv_client = False
class Ecoute(threading.Thread):
def __init__(self, ip, port, Etat_reseau):
threading.Thread.__init__(self)
def run(self):
Serveur()
Client_online = {}
ip = ""
port = 0
fenetre_choix = Tk()
fenetre_choix.title("Panel d'administration")
fenetre_choix.configure(bg = "#00B3D7")
Etat_reseau = StringVar()
Etat_reseau.set("Bon") #0: bon 1:moyen 2:mauvais
info_etat = Label(fenetre_choix, text = "Etat du reseau: Aucun probleme connue" , bg = "#00B3D7")
info_action = Label(fenetre_choix, text = "Action en cours: Aucune", bg = "#00B3D7")
button_bon = Button(fenetre_choix, text = "Aucun probleme connue",font="arial 12 bold",command=Etat_0, bg = "#33FF00", relief=FLAT)
button_moy = Button(fenetre_choix, text = "Presence de ralentissement sur le reseau",font="arial 12 bold", command=Etat_1, bg = "#FFFF00", relief=FLAT)
button_mau = Button(fenetre_choix, text = "Reseau indisponible",font="arial 12 bold",command=Etat_2, bg = "#CC0000", relief=FLAT)
taille_x_l = Label(fenetre_choix, bg = "#00B3D7")
taille_y_b = Label(fenetre_choix, bg = "#00B3D7")
info_ip = Label(fenetre_choix, text = "Quelle est l'etat du reseau ?", bg = "#00B3D7")
info_etat.pack(side=TOP)
info_action.pack(side=TOP,pady=20)
taille_x_l.pack(side=TOP,padx=380)
button_bon.pack(side=TOP,padx=50,pady=10)
button_moy.pack(side=TOP,padx=50,pady=10)
button_mau.pack(side=TOP,padx=50,pady=10)
taille_y_b.pack(side=TOP,pady=40)
info_ip.pack(side=BOTTOM)
newthread_Ecoute = Ecoute(ip, port, Etat_reseau)
newthread_Ecoute.start()
fenetre_choix.mainloop() |
Partager