-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnalyzer.py
executable file
·110 lines (94 loc) · 2.84 KB
/
Analyzer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/env python2
#################################
# #
# Analyzer #
# #
# Francesco Vatteroni #
# #
#################################
import os
import sys
import json
import argparse
import requests
import matplotlib.pyplot as plt
import xml.etree.ElementTree as ET
from datetime import datetime, timedelta
value = {}
def srcVendor(m):
MAC_URL = 'http://macvendors.co/api/%s'
r = requests.get(MAC_URL % m)
obj = r.json()['result']['company']
return obj
def printGrap(d,m):
x = []
y = []
last_d = None
i = 0
s = 0
if d.has_key(m):
d[m].sort(key=lambda tup: tup[0])
for e in d[m]:
current_d = datetime.strptime(e[0][:-7],'%Y-%m-%d %H:%M:%S')
if (last_d is not None) and (last_d - current_d) == timedelta(0):
i = i+1
s = s+int(e[1][:-3])
else :
if (last_d is not None):
x.append(last_d)
y.append(s/i)
last_d = current_d
i = 1
s = int(e[1][:-3])
plt.xticks(rotation = 30)
plt.yticks(rotation = 30)
try:
vendor = srcVendor(m)
except:
vendor = "Nil"
plt.title(vendor + "\n" + m)
plt.plot(x, y)
plt.show()
else:
print "[!] MAC not found"
def parseAll(path):
global value
os.chdir(path)
for filename in os.listdir(path):
if filename.endswith('.xml'):
fullname = filename
root = ET.parse(fullname).getroot()
for child in root:
k = child.attrib.get('value')
for el in child:
time = el[0].text
intes = el[1].text
t = (time, intes)
if value.has_key(k):
value.get(k).append(t)
else:
l = [t]
value[k] = l
def main():
parser = argparse.ArgumentParser(description="https://github.com/The90Frank/PresenceChecker/")
parser.add_argument("-d", "--directory", help="Path to import XML file", type=str, required=True)
parser.add_argument("-m", "--macaddress", help="MAC address to analyze, e.g. 00:11:22:33:44:55", type=str, required=True)
argms = parser.parse_args()
try:
p = os.path.abspath(argms.directory)
except:
parser.print_help()
sys.exit()
try:
parseAll(p)
except:
print "[!] Something was wrong in this folder"
parser.print_help()
sys.exit()
if value:
printGrap(value, argms.macaddress)
else:
print "[!] No Files"
parser.print_help()
sys.exit()
main()