def __init__(self):
        """

        """
        self.devices_ping = {}
        self.session = Session()
        self._create_device_pinger()
Exemplo n.º 2
0
 def __init__(self, if_name, cmds, network=None):
     """
     :param str if_name: name of the interface that shall be used to scan the network
     :param list cmds: list of NMAP commands that shall be used to map the network
     :param IPv4Network network: IPv4Network object that represents the network we want to MAP.
     If the network is not provided, then the interface's address and netmask will be used to identify the network
     """
     super().__init__()
     self.if_name = if_name
     self.if_ip = None
     self.network = network
     self.cmds = cmds
     self.attempts = 0
     self.session = Session()
Exemplo n.º 3
0
def main():
    """
    launches the program
    :return: None
    """
    try:
        session = Session()
        config = get_config_file(CONFIG_FILE)
        map_network(config[NMAP_SECTION])

        agents = start_server_monitoring(config[AGENTS_SECTION], session)

        ping_handler = PingHandler()

        for agent in agents:
            agent.join()

    except Exception as error:
        logging.error("TERMINAL ERROR IN THE MAIN MODULE: %s", error)
        Session.remove()
        engine.dispose()
        sys.exit(-1)
    def run(self):
        """
        Launches the ping every time_btw_ping seconds.
        :return: None
        """
        self._session = Session()
        self.device_presence = self._session.query(DevicePresence).filter_by(
            mac_address=self.device.mac_address).first()
        while self.running:
            try:
                self.ping_device()
                self._session.commit()
                time.sleep(self.time_btw_ping)
            except OSError as error:
                PRESENCE_LOGGER.error(
                    'SCAPY PING PROBLEM. ERROR: %s. PINGING WILL RESTART AFTER %d SLEEP',
                    error, self.time_btw_ping)
                time.sleep(self.time_btw_ping)

            except Exception as error:
                PRESENCE_LOGGER.error(
                    'EXCEPTION IN DEVICE PING. DEVICE IP: %s. DEVICE MAC: %s. ERROR: %s',
                    self.device.ip, self.device.mac_address, error)
                raise