Created
March 11, 2016 12:32
-
-
Save mapcentia/3c753a0068bb013b908a to your computer and use it in GitHub Desktop.
Python script for shipping Kismet logs to GC2
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 sys, re, urllib, urllib2 | |
args =sys.argv | |
filesource = args[1] | |
apikey = args[2] | |
list = []; | |
networks = {}; | |
try: | |
f = open('count','r+') | |
except: | |
w = open('count','w') | |
w.write("0") | |
w.close() | |
f = open('count','r+') | |
count = int(f.read()) | |
#sys.exit() | |
for line in open(filesource, 'r'): | |
if re.match('^Network', line): | |
networks['gid'] = int(line.split(":")[0].split(" ")[1].strip()) | |
networks['mac'] = line.split(" ")[3].strip() | |
if re.match('^ First', line): | |
networks['datetime'] = line.split(" : ")[1].strip() | |
if re.match('^ Type', line): | |
networks['type'] = line.split(":")[1].strip() | |
list.append(networks) | |
networks = {}; | |
for networks in list: | |
networks['device_id']="Martins RPi" | |
print networks | |
sql = "INSERT INTO smartlab.wifi (gid,mac,type,datetime,device_id) VALUES(%d,'%s','%s','%s','%s')" % (networks['gid'],networks['mac'],networks['type'],networks['datetime'],networks['device_id']) | |
data = urllib.urlencode({'q': sql, 'key': apikey}) | |
url = "http://geofyn.mapcentia.com/api/v1/sql/geofyn" | |
if networks['gid'] >= count: | |
try: | |
res = urllib2.urlopen(url, data).read() | |
print res | |
except urllib2.HTTPError, e: | |
print 'HTTPError = ' + str(e.code) | |
f.seek(0) | |
f.write(str(networks['gid'])) | |
f.truncate() | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment