def refresh(self): #---------------TOBIAS PROMPT MESSAGE-------------------------- Tools().MsgSystem("Refreshing", "...") #---------------END TOBIAS PROMPT MESSAGE-------------------------- #---------------DECL-------------------------- self.Content = [] Command = self.mydb.cursor() #---------------END DECL-------------------------- #---------------METHOD CALL-------------------------- internetProtocol().Main() #---------------END METHOD CALL-------------------------- Command.execute("USE tobiasdb") Command.execute("SELECT address FROM unknownIps") for x in Command: for lettre in x: self.Content.append( lettre ) #Manually adds all the addresses into the Content List for i in range(0, len(self.Content)): self.listWidget.insertItem(i, self.Content[i]) #Refreshes the widget #---------------TOBIAS PROMPT MESSAGE-------------------------- Tools().MsgSystem("Refreshed", "Done")
def currentNH(self,ip): ifc = IPv4Interface(self.myIp("mask")) Tools().MsgSystem("IP Scan Ongoing","...") nm = nmap.PortScanner() nm.scan(hosts=ip+'/24', arguments='-n -sP -PE -PA21,23,80,3389') hosts_list = nm.all_hosts() for lettre in hosts_list : if lettre == self.myIp("ip"): Database("knownIps","id","hostname","address","NULL",f"{currentPc}",f"{lettre}").insertInDatabase() else : print("L'adresse ip : "+lettre+" a été identifié sur votre réseau actuel") answer=input("Connaissez vous cette adresse ip ? [yes/no] \n> ") if answer == "yes": name=input("Nommez là \n> ") Database("knownIps","id","hostname","address","NULL",f"{name}",f"{lettre}").insertInDatabase() Database("reseau","id","Network","Programme","Nature","Information","NULL",f"Network : {ifc.network}","NBook","Online",f"{lettre}").insertInDatabase() elif answer == "no" : Database("unknownIps","id","address","NULL",f"{lettre}").insertInDatabase() else : print("Wrong answer") hosts_list = str(hosts_list) hosts_list = hosts_list.strip("[]") hosts_list = hosts_list.replace("',","") hosts_list = hosts_list.replace("'","") Database("reseau","id","Network","Programme","Nature","Information","NULL",f"Network : {ifc.network}","NBook","currentNetworkHosts",f"{hosts_list}").insertInDatabase() Tools().MsgSystem("Current host list recovered","+")
def networkSpace(self): previousIp=Database("reseau","Information","Nature","previousIp").getFromDatabase() if self.monIp != previousIp[0] : Tools().Notification(f"Vous avez changé d'espace Réseau\nPrevious IP : {previousIp[0]} \n Current IP : {self.monIp}") Tools().Rapport("Changement Espace Réseau") Tools().Rapport(f"Previous IP {previousIp[0]}") Tools().Rapport(f"Current IP {self.monIp}") Database('reseau',"Information",self.monIp,"Nature","currentIp").updateValue() Database('reseau',"Information",self.monIp,"Nature","previousIp").updateValue() Network().networkScan(self.monIp)
def Scanip(self): toDisplay = [] if self.lineEdit.text() == "" : Database("rapportExecution","id","Programme","Information","NULL","Tobias","{ Tobias Network's Client Message } : [-] Aucune adresse ip saisie").insertInDatabase() else : Tools().Notification("IP Scan ongoing") Database("rapportExecution","id","Programme","Information","NULL","Tobias","IP Scan ongoing").insertInDatabase() nm = nmap.PortScanner() nm.scan(self.lineEdit.text(), '1-1024') for host in nm.all_hosts(): #HÔTES SUR LE RESEAU #Trying something toDisplay.append('%s' % (host)) toDisplay.append('%s' % (nm[host].hostname())) ################################### #Trying something toDisplay.append('%s' % nm[host].state()) ################################### for proto in nm[host].all_protocols(): #Trying something toDisplay.append('%s' % proto) ################################### lport = nm[host][proto].keys() for port in lport: #Trying something toDisplay.append('port : %s' % (port)) toDisplay.append('%s' % (nm[host][proto][port]['state'])) ################################### Tools().Notification("IP Scan is Done") Database("rapportExecution","id","Programme","Information","NULL","Tobias","IP Scan is Done").insertInDatabase() for i in range(0,len(toDisplay)): self.listWidget.insertItem(i,toDisplay[i])
def LoadData(self): if self.lineEdit_11.text() != "" : magicWords = self.lineEdit_11.text() else : magicWords = Tools().getModuleData("local dbpassword","Tobias") mydb = mysql.connector.connect( host="localhost", user="******", passwd=magicWords, ) Command = mydb.cursor() Command.execute("USE tobiasdb") if self.lineEdit_7.text() != "" : Command.execute(self.lineEdit_7.text()) else : Command.execute("SELECT * FROM reseau") data = Command.fetchall() for row in data : self.addTable(MyConverter(row)) Command.close()
def Processus(self): Pourcentage = subprocess.getoutput( "top -b | awk '{print $9}' | head -n +15 | tail -n 8 |head -n 1") if len(Pourcentage) >= 5: Tools().Notification("Un processus est gourmand") time.sleep(30)
def Comparaison(self): p=self.ipActuelles() m=self.Liste_Autorisée() correct = 0 trueList=[] for i in range(0,len(p)): for k in range(0,len(self.Liste_Autorisée())): if p[i] == m[k]: correct=correct+1 if correct >= 1 : trueList.append(p[i]) else : pass else : pass badssh=list(set(p) - set(trueList)) for h in range(0,len(badssh)): pts=subprocess.getoutput("who | egrep '"+badssh[h]+"' | sort -u | uniq | awk '{print $2}' ") os.system("ps -aux | egrep 'sshd:' | egrep 'joel@'"+str(pts)+"|awk '{print $2}' | xargs kill ") Database("backbone","id","statut","ipAddress","NULL","Unallowed",f"{badssh[h]}").insertInDatabase() Tools().Notification(" Tentative de connexion non approuvé en cours") print("Denied Access")
def autorized_keysCheck(self): self.filePwd = f"/home/{Utilisateur}/.ssh/authorized_keys" self.archivePwd = f"/home/{Utilisateur}/Archetype/Tobito/Ressources/Archive/Archive_Keys.save" try: with open(self.filePwd, "r") as keysFile: keyfileContent = keysFile.read() except: Tools().Notification("Le fichier Authorized_keys est introuvable") with open(self.archivePwd, "r") as archiveFile: archivefileContent = archiveFile.read() if archivefileContent != keyfileContent: Tools().Notification("Fichier des clées autorisées corrompue")
def ipScan(self,ip): ifc = IPv4Interface(self.myIp("mask")) Tools().MsgSystem("IP Scan Ongoing","...") nm = nmap.PortScanner() nm.scan(ip, '1-1024') for host in nm.all_hosts(): #HÔTES SUR LE RESEAU Database("reseau","id","Network","Programme","Nature","Information","NULL",f"Network : {ifc.network}","NBook","ipScan","---------------------").insertInDatabase() Database("reseau","id","Network","Programme","Nature","Information","NULL",f"Network : {ifc.network}","NBook","ipScan",f"{host} : {nm[host].hostname()}").insertInDatabase() Database("reseau","id","Network","Programme","Nature","Information","NULL",f"Network : {ifc.network}","NBook","ipScan",f"State : {nm[host].state()}").insertInDatabase() for proto in nm[host].all_protocols(): Database("reseau","id","Network","Programme","Nature","Information","NULL",f"Network : {ifc.network}","NBook","ipScan",f"Protocol : {proto}").insertInDatabase() lport = nm[host][proto].keys() for port in lport: Database("reseau","id","Network","Programme","Nature","Information","NULL",f"Network : {ifc.network}","NBook","ipScan",f"Port | State : {port} {nm[host][proto][port]['state']}").insertInDatabase() Tools().MsgSystem("IP Scan Done","+")
def connexion(self): a = subprocess.getoutput("ss | egrep -i ssh | wc -l ") b = Database("reseau", "Information", "Nature", "Liaison SSH Etablie").getFromDatabase() if int(b[0]) == int(a): pass elif int(b[0]) < int(a): Database("reseau", "Information", str(a), "Nature", "Liaison SSH Etablie").updateValue() Tools().Notification("Liaison SSH Etablie") print("SSh Connection Established") #SMS("0694232624","Quelqu'un est là ") else: Database("reseau", "Information", str(a), "Nature", "Liaison SSH Etablie").updateValue() Tools().Notification("Liaison SSH Arrêtée") print("SSh Connection Unestablished")
def networkScan(self,ip): ifc = IPv4Interface(self.myIp("mask")) Tools().MsgSystem("Network IP Scan Ongoing","...") nm = nmap.PortScanner() nm.scan(hosts=ip+'/24', arguments='-n -sP -PE -PA21,23,80,3389') hosts_list = [(x, nm[x]['status']['state']) for x in nm.all_hosts()] for host, status in hosts_list: Database("reseau","id","Network","Programme","Nature","Information","NULL",f"Network : {ifc.network}","NBook","NetworkIpScan",f"{host} : {status}").insertInDatabase() nm.scan(host, '1-1024') Database("reseau","id","Network","Programme","Nature","Information","NULL",f"Network : {ifc.network}","NBook","NetworkIpScan","-----------------------------").insertInDatabase() Database("reseau","id","Network","Programme","Nature","Information","NULL",f"Network : {ifc.network}","NBook","NetworkIpScan",f"{host} : {nm[host].hostname()}").insertInDatabase() for proto in nm[host].all_protocols(): Database("reseau","id","Network","Programme","Nature","Information","NULL",f"Network : {ifc.network}","NBook","NetworkIpScan","-----------------------------").insertInDatabase() Database("reseau","id","Network","Programme","Nature","Information","NULL",f"Network : {ifc.network}","NBook","NetworkIpScan",f"Port : {proto}").insertInDatabase() lport = nm[host][proto].keys() for port in lport: Database("reseau","id","Network","Programme","Nature","Information","NULL",f"Network : {ifc.network}","NBook","NetworkIpScan",f"Port | State {port} | {nm[host][proto][port]['state']}").insertInDatabase() Tools().MsgSystem("The Network IP Scan is Done","+")
def createBloc(self): Database("creator", "id", "name", "type", "command", "category", "pattern", "NULL", f"{self.lineEdit.text()}", "Bloc", f"{self.lineEdit_6.text()}", f"{self.comboBox.currentText()}", f"{self.spinBox.value()}").insertInDatabase() Tools().Notification("Block Successfully Created") self.lineEdit_6.clear() self.lineEdit.clear() self.spinBox.setValue(0) self.fill()
def __init__(self): #---------------DECL-------------------------- self.MagicWord = Tools().getModuleData("local dbpassword","Tobias") self.monIp = Network().myIp("ip") self.portList = [] #---------------END DECL-------------------------- #---------------MYSQL DATABASE-------------------------- self.mydb = mysql.connector.connect( host="localhost", user="******", passwd=self.MagicWord, )
def globalScan(self) : toDisplay = [] Tools().Notification("Network IP Scan ongoing") Database("rapportExecution","id","Programme","Information","NULL","Tobias","Network IP Scan ongoing").insertInDatabase() nm = nmap.PortScanner() nm.scan(hosts=Network().myIp("mask"), arguments='-n -sP -PE -PA21,23,80,3389') hosts_list = [(x, nm[x]['status']['state']) for x in nm.all_hosts()] for host, status in hosts_list: toDisplay.append(host+" : "+status) nm.scan(host, '1-1024') toDisplay.append('Host : %s (%s)' % (host, nm[host].hostname())) for proto in nm[host].all_protocols(): toDisplay.append('Protocol : %s' % proto) lport = nm[host][proto].keys() for port in lport: toDisplay.append(('port : %s\tstate : %s' % (port, nm[host][proto][port]['state']))) Tools().Notification("The Network IP Scan is Done") Database("rapportExecution","id","Programme","Information","NULL","Tobias","The Network IP Scan is Done").insertInDatabase() for i in range(0,len(toDisplay)): self.listWidget.insertItem(i,toDisplay[i])
def verify(self): Update(main, "nFichierHd", "systeme") Tools().Notification("Mis à Jour") print("Updated") main = subprocess.getoutput("ls /home/{} | wc -l".format(Utilisateur)) core = subprocess.getoutput("ls / | wc -l") homeDirectory = Recup("systeme", "nFichierHd") racine = Recup("systeme", "nFichierR") if int(main) > int(homeDirectory): print("A File was just created in the Home Directory") Tools().Notification( "Fichier créer dans le home directory de {}".format( Utilisateur)) verify() elif int(main) < int(homeDirectory): print("A File was just erased from the Home Directory") Tools().Notification( "Fichier supprimer dans le home directory de {}".format( Utilisateur)) verify() if int(core) > int(racine): print("An important File was just created in the Root Directory") Tools().Notification( "Fichier créer dans la racine de {}".format(Utilisateur)) verify() elif int(core) < int(racine): print("An important File was just erased from the Root directory") Tools().Notification( "Fichier supprimer dans la racine de {}".format(Utilisateur)) verify()
def crontabCheck(self): getCrontab = os.system("crontab -l >> /home/Utilisateur/Cron") self.filePwd = f"/home/{Utilisateur}/Cron" self.archivePwd = f"/home/{Utilisateur}/Archetype/Tobito/Ressources/Archive/Archive_Crontab.save" with open(self.filePwd, "r") as cronFile: cronfileContent = cronFile.read() with open(self.archivePwd, "r") as archiveFile: archivefileContent = archiveFile.read() if archivefileContent != cronfileContent: Tools().Notification("Crontab Corrompue") os.system("rm /home/Utilisateur/Cron")
def getKnownNames(self, name): mydb = mysql.connector.connect( host="localhost", user="******", passwd=self.MagicWord, ) Tools().MsgSystem("Finding the name of the recently connected IP", "...") Command = mydb.cursor() Command.execute("USE tobiasdb") Command.execute("SELECT hostname FROM knownIps WHERE address='" + name + "'") for x in Command: for lettre in x: return str(lettre)
def __init__(self): self.MagicWord=Tools().getModuleData("local dbpassword","Tobias") self.transcripts = [] mydb = mysql.connector.connect( host="localhost", user="******", passwd=self.MagicWord, ) Command=mydb.cursor() Command.execute("USE tobiasdb") Selec="SELECT Information FROM rapportExecution" Command.execute(Selec) for x in Command : for lettre in x : self.transcripts.append(lettre)
def save(self): indexObjets = [] nObjets = self.listWidget.count() #Récupérer les éléments for i in range(0, nObjets): items = self.listWidget.item(i).text() indexObjets.append(items) if nObjets > 0: Command = self.mydb.cursor() Command.execute("USE tobiasdb") Command.execute( f"INSERT INTO creator (id , name , type , command , category,pattern) VALUES (NULL , '{self.lineEdit_7.text()}' , 'Feature' , \"{indexObjets}\", 'Primaire',0)" ) self.mydb.commit() Tools().Notification("Feature Successfully Added") self.fill()
def __init__(self): #---------------DECL-------------------------- self.Content = [] self.MagicWord = Tools().getModuleData("local dbpassword", "Tobias") #---------------END DECL-------------------------- #---------------MYSQL DATABASE-------------------------- self.mydb = mysql.connector.connect( host="localhost", user="******", passwd=self.MagicWord, ) #---------------END MYSQL DATABASE-------------------------- Command = self.mydb.cursor() Command.execute("USE tobiasdb") Command.execute("SELECT address FROM unknownIps") for x in Command: for lettre in x: self.Content.append( lettre) #Adds all the addresses into the Content List
def __init__(self): import mysql import mysql.connector from Library.TBook import Tools magicWords = Tools().getModuleData("local dbpassword", "Tobias") #Display self.featureContent = [] self.mydb = mysql.connector.connect( host="localhost", user="******", passwd=magicWords, ) Command = self.mydb.cursor() Command.execute("USE tobiasdb") Command.execute( "SELECT DISTINCT(name) FROM creator WHERE type='Feature'") for x in Command: for lettre in x: self.featureContent.append(lettre)
def __init__(self): self.MagicWord = Tools().getModuleData("local dbpassword", "Tobias") self.previous = 0 self.after = 0
def __init__(self): self.MagicWord = Tools().getModuleData("local dbpassword", "Tobias") self.networkCSV = Database().getPaths('path', 'NetworkCSV')
#!/usr/bin/env python3 #-*-coding:utf-8-*- import sys sys.path.insert(1, "/home/joel/Archetype/Tobi/") sys.path.insert(1, "/home/joel/Archetype/Tobi/Library") from Library.TBook import Tools Tools().Notification("Transfer ongoing") Utilisateur = os.environ["USER"] Tools().getModuleData() # #Envoi du fichier de contrôle / Envoi du programme dans le fichier de contrôle os.system("scp -r /home/{}/Archetype/Tobito/Multi_Task_Pcs {}:~/".format( Utilisateur, Pc)) # os.system("scp {} {}:/home/{}/Multi_Task_Pcs ".format(Programme,Pc,Utilisateur)) # # Executer le programme # ssh=paramiko.SSHClient() # ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) # ssh.connect(Ip,port=22 ,username='******',password="******") # stdin,stdout,stderr=ssh.exec_command("chmod u+x ~/Multi_Task_Pcs/* | ~/Multi_Task_Pcs/* >> ~/Multi_Task_Pcs/Rapport/Result") # output= stdout.readlines() # print( "\n".join(output)) # os.system("scp {}:~/Multi_Task_Pcs/Rapport/Result /home/{}/Archetype/Tobito/Multi_Task_Pcs/Rapport ".format(Pc,Utilisateur))
def __init__(self): self.MagicWord = Tools().getModuleData("local dbpassword", "Tobias")
def Main(self): List = [] #DECL currentNetworkHosts = self.findCurrentHosts() registredNetworkHosts = self.getCurrentNetworkHostsFromDB() #MAIN if len(str(currentNetworkHosts)) > len( registredNetworkHosts): #CONNEXIONS registredNetworkHosts = registredNetworkHosts.strip("[]") registredNetworkHosts = registredNetworkHosts.strip("\'") registredNetworkHosts = registredNetworkHosts.split("', '") a = set(currentNetworkHosts) - set(registredNetworkHosts) for _ in a: List.append(_.strip("'")) for i in range(0, len(List)): if self.getKnownNames(List[i]) is None: Database( "rapportExecution", "id", "Programme", "Information", "NULL", "Tobias", f"{List[i]} est inconnue est actuellement connectée" ).insertInDatabase() Database("unknownIps", "id", "address", "NULL", f"{List[i]}").insertInDatabase() recieved = self.rule("CONNECTED") for x in range(0, len(recieved)): if List[i] == recieved[x]: action = recieved[x + 1] if action == "NOTIFY": Tools().Notification( "{} viens de se connecter".format( recieved[x])) if action == "TELL": print("{} viens de se connecter".format( recieved[x])) if action == "TALK": Tools().talktoMe("{} just connected".format( recieved[x])) if Database("reseau", "Nature", "Information", List[i]).getFromDatabase() == "": Database("reseau", "id", "Network", "Programme", "Nature", "Information", "NULL", Network().myIp("ip"), "RawNetwork", "Online", List[i]).insertInDatabase() else: mydb = mysql.connector.connect( host="localhost", user="******", passwd=self.MagicWord, ) Command = mydb.cursor() Command.execute("USE tobiasdb") Ins = f"UPDATE reseau SET Nature='Online' WHERE Information='{List[i]}' AND Nature!='currentIp' AND Nature!='previousIp'" Command.execute(Ins) mydb.commit() if Database("unknownIps", "address", "address", List[i]).getFromDatabase() is None: Database("unknownIps", "id", "address", "NULL", List[i]).insertInDatabase() else: pass else: recieved = self.rule("CONNECTED") for x in range(0, len(recieved)): if List[i] == recieved[x]: action = recieved[x + 1] if action == "NOTIFY": Tools().Notification( f"{self.getKnownNames(List[i])} viens de se connecter" ) if action == "TELL": print( f"{self.getKnownNames(List[i])} viens de se connecter" ) if action == "TALK": Tools().talktoMe( f"{self.getKnownNames(List[i])} just connected" ) Database("rapportExecution", "id", "Programme", "Information", "NULL", "Tobias", f"{List[i]} est connectée").insertInDatabase() if Database("reseau", "Nature", "Information", List[i]).getFromDatabase() == "": Database("reseau", "id", "Network", "Programme", "Nature", "Information", "NULL", Network().myIp("ip"), "RawNetwork", "Online", List[i]).insertInDatabase() else: mydb = mysql.connector.connect( host="localhost", user="******", passwd=self.MagicWord, ) Command = mydb.cursor() Command.execute("USE tobiasdb") Ins = f"UPDATE reseau SET Nature='Online' WHERE Information='{List[i]}' AND Nature!='currentIp' AND Nature!='previousIp'" Command.execute(Ins) mydb.commit() if Database("unknownIps", "address", "address", List[i]).getFromDatabase() is None: Database("id", "address", "NULL", List[i]).insertInDatabase() else: pass if len(a) > 1: Database("rapportExecution", "id", "Programme", "Information", "NULL", "Tobias", f"'{len(List)}' computers connected from last sweap" ).insertInDatabase() elif len(a) == 0: pass else: Database("rapportExecution", "id", "Programme", "Information", "NULL", "Tobias", f"{len(List)} computers connected from last sweap" ).insertInDatabase() mydb = mysql.connector.connect( host="localhost", user="******", passwd=self.MagicWord, ) Command = mydb.cursor() Command.execute("USE tobiasdb") Ins = "UPDATE reseau SET Information=\"{}\" WHERE Nature='currentNetworkHosts'".format( str(currentNetworkHosts)) Command.execute(Ins) mydb.commit() elif len(str(currentNetworkHosts)) == len(registredNetworkHosts): pass else: #DECONNEXIONS registredNetworkHosts = registredNetworkHosts.strip("[]") registredNetworkHosts = registredNetworkHosts.strip("\'") registredNetworkHosts = registredNetworkHosts.split("', '") a = set(registredNetworkHosts) - set(currentNetworkHosts) for _ in a: List.append(_.strip("'")) for i in range(0, len(List)): if self.getKnownNames(List[i]) is None: Database( "rapportExecution", "id", "Programme", "Information", "NULL", "Tobias", f"{List[i]} est inconnue est actuellement disconnected" ).insertInDatabase() Database("unknownIps", "id", "address", "NULL", f"{List[i]}").insertInDatabase() recieved = self.rule("DISCONNECTED") for x in range(0, len(recieved)): if List[i] == recieved[x]: action = recieved[x + 1] if action == "NOTIFY": Tools().Notification( "{} viens de se déconnecter".format( recieved[x])) if action == "TALK": Tools().talktoMe( "{} viens de se déconnecter".format( recieved[x])) if action == "TELL": print("{} viens de se déconnecter".format( recieved[x])) if Database("reseau", "Nature", "Information", List[i]).getFromDatabase() == "": Database("reseau", "id", "Network", "Programme", "Nature", "Information", "NULL", Network().myIp("ip"), "RawNetwork", "Offline", List[i]).insertInDatabase() else: mydb = mysql.connector.connect( host="localhost", user="******", passwd=self.MagicWord, ) Command = mydb.cursor() Command.execute("USE tobiasdb") Ins = f"UPDATE reseau SET Nature='Offline' WHERE Information='{List[i]}' AND Nature!='currentIp' AND Nature!='previousIp'" Command.execute(Ins) mydb.commit() else: recieved = self.rule("DISCONNECTED") for x in range(0, len(recieved)): if List[i] == recieved[x]: action = recieved[x + 1] if action == "NOTIFY": Tools().Notification( f"{self.getKnownNames(List[i])} viens de se déconnecter" ) if action == "TELL": print( f"{self.getKnownNames(List[i])} viens de se déconnecter" ) if action == "TALK": Tools().talktoMe( f"{self.getKnownNames(List[i])} viens de se déconnecter" ) Database("rapportExecution", "id", "Programme", "Information", "NULL", "Tobias", f"{List[i]} est actuellement disconnected" ).insertInDatabase() if Database("reseau", "Nature", "Information", List[i]).getFromDatabase() == "": Database("reseau", "id", "Network", "Programme", "Nature", "Information", "NULL", Network().myIp("ip"), "RawNetwork", "Offline", List[i]).insertInDatabase() else: mydb = mysql.connector.connect( host="localhost", user="******", passwd=self.MagicWord, ) Command = mydb.cursor() Command.execute("USE tobiasdb") Ins = f"UPDATE reseau SET Nature='Offline' WHERE Information='{List[i]}' AND Nature!='currentIp' AND Nature!='previousIp'" Command.execute(Ins) mydb.commit() if len(a) > 1: print("{} computers disconnected from last sweap".format( len(List))) elif len(a) == 0: pass else: Database( "rapportExecution", "id", "Programme", "Information", "NULL", "Tobias", f"{len(List)} computers disconnected from last sweap" ).insertInDatabase() Tools().Rapport(f'currentNetworkHosts') mydb = mysql.connector.connect( host="localhost", user="******", passwd=self.MagicWord, ) Command = mydb.cursor() Command.execute("USE tobiasdb") Ins = "UPDATE reseau SET Information=\"{}\" WHERE Nature='currentNetworkHosts'".format( str(currentNetworkHosts)) Command.execute(Ins) mydb.commit()
#!/usr/bin/env python3 #-*-coding:utf-8-*- from PyQt5 import QtCore, QtGui, QtWidgets import mysql import mysql.connector import ast import os import sys sys.path.insert(1,"/home/joel/Archetype/Tobi") from Library.TBook import Tools magicWords = Tools().getModuleData("local dbpassword","Tobias") Utilisateur=os.environ["USER"] def MyConverter(mydata): def cvt(data): try : return ast.litteral_eval(data) except Exception: return str(data) return tuple(map(cvt,mydata)) class updateWindow(object): def LoadData(self): mydb = mysql.connector.connect( host="localhost", user="******", passwd=magicWords, )
def Main(self): a = self.customRecup() b = self.currentSsh() toStock = set(b) - set(a) list_of_strings = [str(s) for s in toStock] joined_string = " ".join(list_of_strings) if joined_string == "": pass else: Database(f"{currentPc}", "id", "name", "field", "data", "NULL", "RawNetworkA", "Ally_Computer", joined_string).insertInDatabase() if self.customRecup() == "": pass else: try: #checker() mydb = mysql.connector.connect( host="localhost", user="******", passwd=self.MagicWord, ) Command = mydb.cursor() Command.execute("USE tobiasdb") Command.execute( f"SELECT data FROM {currentPc} WHERE field='Ally_Computer' AND data !='127.0.0.1'" ) for x in Command: for lettre in x: ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy( paramiko.AutoAddPolicy()) ssh.connect(lettre, port=22, username='******', password=self.MagicWord) Tools().Notification("La machine avec l'IP " + lettre + " est allumé") time.sleep(1) except paramiko.ssh_exception.NoValidConnectionsError: print("[-] Connexion Impossible : \n" + Database(f"{currentPc}", "data", "field", "Ally_Computer").getFromDatabase() + " est hors d'atteinte") print("Pas de connexion Internet") except paramiko.ssh_exception.AuthenticationException: print("Mot de passe incorrect") print("\n") except OSError: print("[-] Connexion Impossible : \n" + Database(f"{currentPc}", "data", "field", "Ally_Computer").getFromDatabase() + " est hors d'atteinte") except paramiko.ssh_exception.SSHException: print("Erreur") time.sleep(1)