-
Notifications
You must be signed in to change notification settings - Fork 1
/
6-1.py
75 lines (56 loc) · 2.19 KB
/
6-1.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
import pyshark
import csv
import collections
import os
def sh(script):
os.system("bash -c '%s'" % script)
caps = pyshark.FileCapture('200302161400.dump' , display_filter='(udp) and (not udp.port==53 and not udp.port==67 and not udp.port==68 and not icmp)')
cntr = 0
src_ips = []
dst_ips = []
src_ports = []
dst_ports = []
# with open('data.csv', 'w', encoding='UTF8') as f:
# writer = csv.writer(f)
# writer.writerow(['srcip' , 'dstip' , 'srcport' , 'dstport' , 'srcmac' , 'dstmac'])
# for c in caps:
# row = []
# row.append(c['ip'].src)
# row.append(c['ip'].dst)
# row.append(c['udp'].srcport)
# row.append(c['udp'].dstport)
# # row.append(c['eth'].src)
# # row.append(c['eth'].dst)
# writer.writerow(row)
# cntr = cntr + 1
# with open('mac.csv', 'w', encoding='UTF8') as f:
# writer = csv.writer(f)
# writer.writerow(['srcMAC' , 'dstMAC'])
# for c in caps:
# row = []
# row.append(c['eth'].src)
# row.append(c['eth'].dst)
# writer.writerow(row)
# cntr = cntr + 1
# with open('Part4.csv', 'w', encoding='UTF8') as f:
# writer = csv.writer(f)
# writer.writerow(['srcIP' , 'dstIP'])
# for c in caps:
# row = []
# row.append(c['ip'].src)
# row.append(c['ip'].dst)
# writer.writerow(row)
print("number of suspicious packages is ==> ")
sh("wc -l data.csv")
with open('data.csv') as f:
next(f) # Skip the first line
print("most 10 dst port use in network ==> " , collections.Counter(line.rstrip().rpartition(',')[-1] for line in f).most_common(10) )
with open('Part4.csv') as f:
next(f) # Skip the first line
print("most 10 ip in network ==> " , collections.Counter(line.rstrip().rpartition(',')[0] for line in f).most_common(10) )
with open('mac.csv') as f:
next(f) # Skip the first line
print("most 10 mac src use in network ==> " , collections.Counter(line.rstrip().rpartition(',')[0] for line in f).most_common(10) )
with open('Part4.csv') as f:
next(f) # Skip the first line
print("most 7 pair ip in network ==> " , collections.Counter(line for line in f).most_common(7) )