четверг, 31 мая 2018 г.

Статистика производителей Wi-Fi точек доступа из базы kismet.



import sqlite3
import codecs
import sys
from collections import Counter
from tabulate import tabulate

con = sqlite3.connect('wireless.dbl')

cur = con.cursor()
cur.execute("SELECT Manuf FROM wireless")

rows = cur.fetchall()

stat = []
for row  in rows:
    st = row[0]
    stat.append(row[0])


c = Counter(stat)

l = []
for key in sorted(c.iterkeys()):
    l.append([key, c[key]])

sum=0
for vend in l:
    venst=str(vend[0]).rstrip('\n')
    sum=sum+vend[1]
#    print (venst+", "+str(vend[1]))
#print ("Total AP:"+sum)

percent=[]
for perc in l:
    venndd = str(perc[0]).rstrip('\n')
    numb = perc[1]
    perce = 100 * float(numb)/float(sum)
    percent.append([venndd, perce, numb])
#    print (percent)  

#print (l)
#print tabulate(percent, headers=['Vendor', "Percent of total", 'Total'], tablefmt='orgtbl')

#print filter(lambda x: 'Ubiquti' in x, percent)
#print (sortvend)

#print (sys.argv[1])
print tabulate(filter(lambda x: sys.argv[1] in x, percent), headers=['Vendor', "Percent of total", 'Total'], tablefmt='orgtbl')

Комментариев нет:

Отправить комментарий