blob: 2bd28e2e6209f009b2de4e601b9cee87bb23157b [file] [log] [blame]
Chetan Gaonkereb2b24b2016-03-01 14:04:45 -08001import threading
2import sys
3import os
4import time
5import monotonic
6from scapy.all import *
7
8class McastTraffic(threading.Thread):
9
10 dst_mac = '01:00:5e:00:01:01'
11 src_mac = '02:88:b4:e4:90:77'
12 src_ip = '1.2.3.4'
13 SEND_STATE = 1
14 RECV_STATE = 2
15 def __init__(self, addrs, iface = 'eth0', cb = None, arg = None):
16 threading.Thread.__init__(self)
17 self.addrs = addrs
18 self.iface = iface
19 self.cb = cb
20 self.arg = arg
21 self.state = self.SEND_STATE | self.RECV_STATE
22
23 def run(self):
24 eth = Ether(dst = self.dst_mac, src = self.src_mac)
25 while self.state & self.SEND_STATE:
26 for addr in self.addrs:
27 #data = repr(time.time())
28 data = repr(monotonic.monotonic())
29 ip = IP(dst = addr, src = self.src_ip)
30 sendp(eth/ip/data, iface = self.iface)
31 if self.cb:
32 self.cb(self.arg)
33
34 def stop(self):
35 self.state = 0
36
37 def stopReceives(self):
38 self.state &= ~self.RECV_STATE
39
40 def stopSends(self):
41 self.state &= ~self.SEND_STATE
42
43 def isRecvStopped(self):
44 return False if self.state & self.RECV_STATE else True
45
46 def isSendStopped(self):
47 return False if self.state & self.SEND_STATE else True
48
49