MCPcopy Create free account
hub / github.com/PierreGode/Ragnar / sql_connect

Method sql_connect

actions/sql_connector.py:107–134  ·  view source on GitHub ↗

Attempt to connect to an SQL service using the given credentials without specifying a database.

(self, adresse_ip, user, password)

Source from the content-addressed store, hash-verified

105 self.scan = pd.DataFrame(columns=['MAC Address', 'IPs', 'Hostnames', 'Ports', 'Alive'])
106 # Ensure Ports column is string type before using .str accessor
107 self.scan["Ports"] = self.scan["Ports"].astype(str)
108 self.scan = self.scan[self.scan["Ports"].str.contains("3306", na=False)]
109
110 def sql_connect(self, adresse_ip, user, password):
111 """
112 Attempt to connect to an SQL service using the given credentials without specifying a database.
113 """
114 try:
115 # Première tentative sans spécifier de base de données
116 conn = pymysql.connect(
117 host=adresse_ip,
118 user=user,
119 password=password,
120 port=3306
121 )
122
123 # Si la connexion réussit, récupérer la liste des bases de données
124 with conn.cursor() as cursor:
125 cursor.execute("SHOW DATABASES")
126 databases = [db[0] for db in cursor.fetchall()]
127
128 conn.close()
129 logger.info(f"Successfully connected to {adresse_ip} with user {user}")
130 logger.info(f"Available databases: {', '.join(databases)}")
131
132 # Sauvegarder les informations avec la liste des bases trouvées
133 return True, databases
134
135 except pymysql.Error as e:
136 logger.error(f"Failed to connect to {adresse_ip} with user {user}: {e}")
137 return False, []

Callers 2

workerMethod · 0.95
_verify_credentialsMethod · 0.80

Calls 7

cursorMethod · 0.80
infoMethod · 0.80
errorMethod · 0.80
connectMethod · 0.45
executeMethod · 0.45
fetchallMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected