def __init__(self, super_socket=None, reactor=None, timeout=None, receive=True): abstract.FileDescriptor.__init__(self, reactor) # By default we use the conf.L3socket if not super_socket: super_socket = conf.L3socket() self.super_socket = super_socket self.timeout = timeout # This dict is used to store the unique hashes that allow scapy to # match up request with answer self.hr_sent_packets = {} # These are the packets we have received as answer to the ones we sent self.answered_packets = [] # These are the packets we send self.sent_packets = [] # This deferred will fire when we have finished sending a receiving packets. self.d = defer.Deferred() self.debug = False self.multi = False # XXX this needs to be implemented. It would involve keeping track of # the state of the sending via the super socket file descriptor and # firing the callback when we have concluded sending. Check out # twisted.internet.udp to see how this is done. self.receive = receive
def __enter__(self): self._socket = conf.L3socket(iface=self._interface) return self
def send(x, filter=None, iface=None, nofilter=0, timeout=None): super_socket = conf.L3socket(filter=filter, iface=iface, nofilter=nofilter) sp = ScapyProtocol(super_socket=super_socket, timeout=timeout) return sp.startSending(x)
def __init__( # pylint: disable=too-many-arguments self, amq_host: str, amq_queue: str, amq_port: int = 5672, amq_vhost: str = "/", amq_username: str = "guest", amq_password: str = "guest", amq_prefetch: int = 1000, udp_host: str = "127.0.0.1", udp_port: int = 514, exclude_patterns: Optional[List] = None, ) -> None: assert isinstance( amq_host, str) and amq_host, "amq_host parameter must be a non-empty string" assert isinstance( amq_queue, str ) and amq_queue, "amq_queue parameter must be a non-empty string" assert isinstance( amq_port, int ) and 1 <= amq_port <= 65535, "amq_port parameter must be an integer between 1 and 65535" assert isinstance( amq_vhost, str ) and amq_vhost, "amq_vhost parameter must be a non-empty string" assert isinstance( amq_username, str ) and amq_username, "amq_username parameter must be a non-empty string" assert isinstance( amq_password, str ) and amq_password, "amq_password parameter must be a non-empty string" assert isinstance( amq_prefetch, int ) and amq_prefetch > 0, "amq_prefetch parameter must be a positive integer" assert isinstance( udp_host, str) and udp_host, "udp_host parameter must be a non-empty string" assert isinstance( udp_port, int ) and 1 <= udp_port <= 65535, "udp_port parameter must be an integer between 1 and 65535" assert ( exclude_patterns is None or isinstance(exclude_patterns, list) and all(isinstance(x, str) and x for x in exclude_patterns) ), "exclude_patterns parameter must be None or a list of non-empty strings" self.amq_host = amq_host self.amq_queue = amq_queue self.amq_port = amq_port self.amq_vhost = amq_vhost self.amq_username = amq_username self.amq_password = amq_password self.amq_prefetch = amq_prefetch self.udp_host = udp_host self.udp_port = udp_port if exclude_patterns is None: exclude_patterns = [] self.exclude_patterns = exclude_patterns self.exclude_patterns_bytes = [ bytes(x, "utf-8") for x in self.exclude_patterns ] self.logger = logging.getLogger(self.__class__.__name__) # For periodic stats logger self.consume_log_count = 0 self.consume_log_dt = self.utc_now self.socket = conf.L3socket()