Пример #1
0
    def __init__(self, logger, interface, pidfile, stdout, stderr):
        """Initialises several things needed to define the daemons behaviour.

        Args:
            logger (logging.Logger): Used for logging messages.
            interface (str): The network interface which should be used. (e.g. eth0)
            pidfile (str): Path of the pidfile, used by the daemon.
            stdout (str): Path of stdout, used by the daemon.
            stderr (str): Path of stderr, used by the daemon.

        Raises:
            DaemonError: Signalises the failure of the daemon.
        """
        super(self.__class__, self).__init__(logger, interface, pidfile, stdout, stderr)
        self.redis = ApateRedis(str(self.network.network), logger)

        # Initialise threads
        self.sniffthread = SelectiveSniffThread(self.interface, self.gateway, self.mac, self.gate_mac, self.redis)
        self.sniffthread.daemon = True
        self.psthread = PubSubThread(self.redis, self.logger)
        self.psthread.daemon = True
        self.arpthread = ARPDiscoveryThread(self.gateway, str(self.network.network))
        self.arpthread.daemon = True
        self.igmpthread = IGMPDiscoveryThread(self.gateway, str(self.network.network), self.ip, self.mac)
        self.igmpthread.daemon = True
Пример #2
0
    def __init__(self, logger, interface, ipv6):
        """Initialises several things needed to define the daemons behaviour.

        Args:
            logger (logging.Logger): Used for logging messages.
            interface (str): The network interface which should be used. (e.g. eth0)
            pidfile (str): Path of the pidfile, used by the daemon.
            stdout (str): Path of stdout, used by the daemon.
            stderr (str): Path of stderr, used by the daemon.
            dns_file (str): Path of file containing the nameservers.

        Raises:
            DaemonError: Signalises the failure of the daemon.
        """
        super(self.__class__, self).__init__()

        self.exit = mp.Event()

        self.interface = interface
        self.logger = logger

        # add redis objects to the ip tuples
        self.ipv6 = ipv6._replace(
            redis=ApateRedis(str(ipv6.network.network), logger))

        # used for thread synchronisation (for waking this thread)
        self.sleeper = threading.Condition()

        self.threads = {}
        # Initialise threads
        self.threads['sniffthread'] = SelectiveIPv6SniffThread(
            self.interface, self.ipv6, self.sleeper, self.logger)
        self.threads['icmpv6thread'] = MulticastPingDiscoveryThread(
            self.interface)
        self.threads['mldv2thread'] = MulticastListenerDiscoveryThread(
            self.interface)
        self.threads['psthread6'] = PubSubThread(self.ipv6, self.logger,
                                                 self.spoof_devices)

        # declare all threads as deamons
        for worker in self.threads:
            self.threads[worker].daemon = True