I'm currently looking at developing a client app in Python. I have a server app developed in C++ that captures wifi data and then my app connects to the server and grabs the data relating to the wifi access points and then inserts this into a MySQL DB. Here's my code thusfar:
#!/usr/bin/python import socket import sys import re import MySqldb import syslog import logging import time # MySQL Server connection settings conn = MySQLdb.connect (host = "localhost", user = "root", passwd = "toor", db = "testdb") # Kismet server settings host = 'localhost' port = 2501 # Create a TCP socket s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((host, port)) cursor = conn.cursor () cursor.execute ("DROP TABLE IF EXISTS data") cursor.execute (""" CREATE TABLE data ( mac CHAR(40), bssid CHAR(40), contype CHAR(40), ip CHAR(40), ltime CHAR(40) ) """) #Start loop to grab client information from Kismet server while 1: s.send('\n!0 enable client mac,bssid,type,ip,lasttime') buff = s.recv(512) tmp = buff.split() mac = tmp bssid = tmp contype = tmp ip = tmp ltime = tmp c.execute( """INSERT INTO data (mac, bssid, contype, ip, ltime) VALUES (%s, %s, %s, %s, %s)""", ) conn.close() cursor.close() s.close()
My code appears to work (in the sense that it doesn't crash. Likewise, the onscreen printout of the server app shows that the connection is successful. My tables and columns are successfully created too in MySQL. The problem is that the data being sent over the socket (mac, bssid, contype, ip, ltime) are not being inserted into the MySQL DB. The server is detecting wireless access points as the existing client written in C++ confirms this. I have to assume there is an error in my code around this part:-
c.execute( """INSERT INTO data (mac, bssid, contype, ip, ltime) VALUES (%s, %s, %s, %s, %s)""",
I assume I am missing some key info here which will instruct the app to insert the streamed data into the DB.