forked from fin/plinker
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.py
More file actions
44 lines (35 loc) · 1010 Bytes
/
test.py
File metadata and controls
44 lines (35 loc) · 1010 Bytes
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
import pcapy
from scapy.layers.all import IP, Ether,ICMP, TCP
import pydb
import netifaces
import OSC # pyOSC
interface = 'wlan0'
interface_address = netifaces.ifaddresses(interface)[2][0]['addr']
print interface_address
p = pcapy.open_live(interface, 1024, False, 10240)
#p = pcapy.open_offline('test.tcpdump')
summary_in = {}
summary_out = {}
try:
(header, payload) = p.next()
while header:
e = Ether(payload)
t = e.getlayer(TCP)
if t:
i = e.getlayer(IP)
if i.dst==interface_address:
summary_in.setdefault(t.dport,0)
summary_in[t.dport]+=1
else:
summary_out.setdefault(t.dport,0)
summary_out[t.dport]+=1
if e.haslayer(ICMP):
print 'ping'
second = header.getts()[0] # [1] = miliseconds
(header, payload) = p.next()
except KeyboardInterrupt:
pass
except Exception,e:
print e
print summary_in
print summary_out