Guest User

Untitled

a guest
Apr 17th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. import mysql.connector as mariadb #to configure the whole SQL connectino
  2. import time #for the strftime function
  3. print(""" __ __.__ .__ ________ __ .__ .__
  4. / \ / \__|______ ____ | | ____ ______ ______ / _____/_____ _/ |_| |__ ___________|__| ____ ____
  5. \ \/\/ / \_ __ \_/ __ \| | _/ __ \ / ___// ___/ / \ ___\__ \\ __\ | \_/ __ \_ __ \ |/ \ / ___\
  6. \ /| || | \/\ ___/| |_\ ___/ \___ \ \___ \ \ \_\ \/ __ \| | | Y \ ___/| | \/ | | \/ /_/ >
  7. \__/\ / |__||__| \___ >____/\___ >____ >____ > \______ (____ /__| |___| /\___ >__| |__|___| /\___ /
  8. \/ \/ \/ \/ \/ \/ \/ \/ \/ \//_____/ """)
  9. 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
  10. #creating new variables to add in the SQL query
  11. now = time.strftime('%Y-%m-%d %H:%M:%S') #use current time
  12. wifichannel = 6 #assign a list of variables to execute the query later
  13. security = "PSK"
  14. ssid = "not eduroam"
  15. hostname ="naam"
  16. signalstrength="-30dbm"
  17. macaddress="44:40:40:40:AB:44:55:DD"
  18. values = (macaddress, signalstrength, hostname, ssid, security, wifichannel, now) #assign all variables in a tuple for the VALUES part of the SQL-query
  19.  
  20. sql_insert_query = """ INSERT INTO `details`
  21. (`macaddress`,`signalstrength`,`hostname`,`ssid`,`security`,`wifichannel`,`timestamp`) VALUES (%s, %s, %s, %s, %s, %s, %s)""" #preparing the query
  22.  
  23. cursor = mariadb_connection.cursor() #connect to execute query
  24. result = cursor.execute(sql_insert_query, values) #execute the SQL query with the assigned vars
  25. mariadb_connection.commit() #commit to server
  26.  
  27.  
  28. print("Record inserted successfully, containing the following information: \n" + str(values)) #feedback in term
  29. #ENDLOOP
  30.  
  31.  
  32. if (mariadb_connection.is_connected()): #close the connection for security purposes when done
  33. cursor.close()
  34. mariadb_connection.close()
  35. print(" Connection is closed")
Add Comment
Please, Sign In to add comment