blob: 7ab79a7e0a41699ac6598889fe9506c208802a07 [file] [log] [blame]
import threading
import sys
import os
import time
import monotonic
from scapy.all import *
class McastTraffic(threading.Thread):
DST_MAC_DEFAULT = '01:00:5e:00:01:01'
SRC_MAC_DEFAULT = '02:88:b4:e4:90:77'
SRC_IP_DEFAULT = '1.2.3.4'
SEND_STATE = 1
RECV_STATE = 2
def __init__(self, addrs, iface = 'eth0', dst_mac = DST_MAC_DEFAULT, src_mac = SRC_MAC_DEFAULT,
src_ip = SRC_IP_DEFAULT, cb = None, arg = None):
threading.Thread.__init__(self)
self.addrs = addrs
self.iface = iface
self.dst_mac = dst_mac
self.src_mac = src_mac
self.src_ip = src_ip
self.cb = cb
self.arg = arg
self.state = self.SEND_STATE | self.RECV_STATE
def run(self):
eth = Ether(dst = self.dst_mac, src = self.src_mac)
while self.state & self.SEND_STATE:
for addr in self.addrs:
#data = repr(time.time())
data = repr(monotonic.monotonic())
ip = IP(dst = addr, src = self.src_ip)
sendp(eth/ip/data, iface = self.iface)
if self.cb:
self.cb(self.arg)
def stop(self):
self.state = 0
def stopReceives(self):
self.state &= ~self.RECV_STATE
def stopSends(self):
self.state &= ~self.SEND_STATE
def isRecvStopped(self):
return False if self.state & self.RECV_STATE else True
def isSendStopped(self):
return False if self.state & self.SEND_STATE else True