Created
June 6, 2016 15:57
-
-
Save peterretief/37f90421f3b0bca60ffb7f128b10bbf0 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/python | |
#might need re at some point | |
#import re | |
#sql | |
#SELECT * FROM ipdata where ipaddress1="192.168.0.137" | |
#SELECT ipaddress1, sum(upload), sum(download) FROM ipdata group by ipaddress1 | |
#SELECT ipaddress2, sum(upload), sum(download) FROM ipdata group by ipaddress2 | |
import urllib2 | |
import sqlite3 | |
#add full path for CROn to work | |
conn = sqlite3.connect('/home/peter/ROUTER/ACCOUNTING/usage.db') | |
c = conn.cursor() | |
#mikrotik ip address accouting | |
url = 'http://192.168.0.1/accounting/ip.cgi' | |
req = urllib2.Request(url) | |
f = urllib2.urlopen(req) | |
for x in f: | |
list = [] | |
for line in x.split("\n"): | |
var_ipadd1 = "" | |
var_ipadd2 = "" | |
var_upload = "" | |
var_download = "" | |
cnt = 0 | |
for ipadd in line.split(" "): | |
cnt = cnt + 1 | |
if ipadd: | |
if (cnt == 1) and ipadd: | |
var_ipadd1 = ipadd | |
if (cnt == 2)and ipadd: | |
var_ipadd2 = ipadd | |
if (cnt == 3) and ipadd: | |
var_upload = ipadd | |
if (cnt == 4) and ipadd: | |
var_download = ipadd | |
testsc = [(var_ipadd1, var_ipadd2, var_upload, var_download),] | |
c.executemany('INSERT INTO ipdata(ipaddress1,ipaddress2,upload,download) \ | |
VALUES (?,?,?,?)', testsc) | |
conn.commit() | |
conn.close() | |
print "success" | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment