forked from dhoelzer/ShowMeThePackets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
freq.py
executable file
·42 lines (38 loc) · 1.09 KB
/
freq.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
import numpy as np
import matplotlib.pyplot as plt
import sys
import argparse
parser = argparse.ArgumentParser(description="Generate time domain and frequency domain plots of the input data.")
parser.add_argument('-w','--window', default=60.0, type=float, dest="window", help="Define the time window for the time domain histogram and frequency analysis.")
window = parser.parse_args().window
bin=0
startingTime = 0.0
endingTime = 0.0
binLimit=-1.0
samples = 0
timeDomain = []
for line in sys.stdin:
(timestamp, host)=line.split(" ")
ts = float(timestamp)
if(binLimit == -1.0):
startingTime = ts
binLimit = ts + window
samples = 1
timeDomain.append(0)
while(ts > binLimit):
timeDomain.append(0)
samples += 1
bin += 1
binLimit += window
if(ts <= binLimit):
timeDomain[bin] += 1
samples += 1
endingTime = ts
if bin % 2 == 1:
bin+=1
timeDomain.append(0)
seconds = [float(n) * window for n in range(0,len(timeDomain))]
plt.plot(seconds,timeDomain)
plt.title("Packets over time")
plt.xlabel("Seconds")
plt.show()