Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import mysql.connector as mariadb #to configure the whole SQL connectino
- import time #for the strftime function
- print(""" __ __.__ .__ ________ __ .__ .__
- / \ / \__|______ ____ | | ____ ______ ______ / _____/_____ _/ |_| |__ ___________|__| ____ ____
- \ \/\/ / \_ __ \_/ __ \| | _/ __ \ / ___// ___/ / \ ___\__ \\ __\ | \_/ __ \_ __ \ |/ \ / ___\
- \ /| || | \/\ ___/| |_\ ___/ \___ \ \___ \ \ \_\ \/ __ \| | | Y \ ___/| | \/ | | \/ /_/ >
- \__/\ / |__||__| \___ >____/\___ >____ >____ > \______ (____ /__| |___| /\___ >__| |__|___| /\___ /
- \/ \/ \/ \/ \/ \/ \/ \/ \/ \//_____/ """)
- mariadb_connection = mariadb.connect(host='192.168.19.131', user='root', password='123qwerty', database="details") #set up conn to db. Change IP-address if neccessary
- #creating new variables to add in the SQL query
- now = time.strftime('%Y-%m-%d %H:%M:%S') #use current time
- wifichannel = 6 #assign a list of variables to execute the query later
- security = "PSK"
- ssid = "not eduroam"
- hostname ="naam"
- signalstrength="-30dbm"
- macaddress="44:40:40:40:AB:44:55:DD"
- values = (macaddress, signalstrength, hostname, ssid, security, wifichannel, now) #assign all variables in a tuple for the VALUES part of the SQL-query
- sql_insert_query = """ INSERT INTO `details`
- (`macaddress`,`signalstrength`,`hostname`,`ssid`,`security`,`wifichannel`,`timestamp`) VALUES (%s, %s, %s, %s, %s, %s, %s)""" #preparing the query
- cursor = mariadb_connection.cursor() #connect to execute query
- result = cursor.execute(sql_insert_query, values) #execute the SQL query with the assigned vars
- mariadb_connection.commit() #commit to server
- print("Record inserted successfully, containing the following information: \n" + str(values)) #feedback in term
- #ENDLOOP
- if (mariadb_connection.is_connected()): #close the connection for security purposes when done
- cursor.close()
- mariadb_connection.close()
- print(" Connection is closed")
Add Comment
Please, Sign In to add comment