Last active
August 13, 2017 16:42
-
-
Save rotemtam/9ca5e26d6989ad7f5da7 to your computer and use it in GitHub Desktop.
Send airodump-ng csv data to firebase db
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess, StringIO, csv | |
from simplejson import dumps | |
from firebase import Firebase | |
from time import sleep, time | |
# to install Firebase, pip install -e git://github.com/mikexstudios/python-firebase.git#egg=python-firebase | |
firebase = Firebase('https://<your_app>.firebaseio.com/stations') | |
def fetch_data(): | |
# get the newest capture.csv file, then use awk to get only Station data | |
cmd = r"cat /tmp/`ls -Art /tmp | grep capture | tail -n 1` | awk '/Station/{y=1;next}y'" | |
data = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE).stdout.read() | |
f = StringIO.StringIO(data) | |
# convert the data to a list of dict() objects | |
conv = lambda row: {'station_mac':row[0], 'first_time_seen':row[1], 'last_time_seen':row[2], 'power':row[3]} | |
data = [row for row in csv.reader(f, delimiter=',') if len(row) != 0] | |
return [conv(row) for row in data] | |
while True: | |
print firebase.put(fetch_data()) | |
sleep(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment