示例#1
0
def malware_get_reputation_ip(ip: str, loggers: logging) -> int:
    """
    Metodo para reguntar por la reputacion de una ip, te devuelve el numero de ataques que se han recibido de esa ip
    o -2 en caso de no recibir ninguno y -1 si falla la precion
    :param ip:
    :param loggers:
    :return:
    """
    url_api = "http://127.0.0.1:8080"
    url = f'{url_api}/getReputationIp?ip={ip}'
    headers = {'Accept': 'application/json'}
    try:
        r = requests.get(url, headers=headers, timeout=5)
        if r.status_code == 200:
            # try:
            return json.loads(r.text)['reputation']
        # except json.decoder.JSONDecodeError:
        else:
            return -1
    except (requests.exceptions.ConnectionError,
            requests.exceptions.ReadTimeout):
        # print(f"No se ha podido comprobar la reputacion para {ip}")  # no se tiene acceso a logger
        loggers.warning(f"No se ha podido comprobar la reputacion para {ip}"
                        )  # fixme traducir
        return -1
示例#2
0
    def __init__(self, log_dir: Union[str, Path], logger: logging, enable: bool = True):
        self.writer = None
        if enable:
            log_dir = str(log_dir)
            try:
                self.writer = importlib.import_module("tensorboardX").SummaryWriter(
                    log_dir
                )
            except ImportError:
                message = (
                    "Warning: TensorboardX visualization is configured to use, but currently not installed on "
                    "this machine. Please install the package by 'pip install tensorboardx' command or turn "
                    "off the option in the 'config.json' file."
                )
                logger.warning(message)
        self.step = 0
        self.mode = ""

        self.tb_writer_ftns = [
            "add_scalar",
            "add_scalars",
            "add_image",
            "add_images",
            "add_audio",
            "add_text",
            "add_histogram",
            "add_pr_curve",
            "add_embedding",
        ]
        self.tag_mode_exceptions = ["add_histogram", "add_embedding"]
        self.timer = Timer()
示例#3
0
def get_number_lines_file(file: str, loggers: logging) -> int:
    try:
        command = f'wc -l {file} | cut -d " " -f1'
        execute = subprocess.Popen(command,
                                   shell=True,
                                   stdout=subprocess.PIPE,
                                   stderr=subprocess.PIPE)
        stdout, stderr = execute.communicate()
        count_lines = int(stdout)
        print(count_lines)
        return count_lines
    except Exception as e:
        loggers.warning(e)
        loggers.warning('Method readlines')
        with open(file, 'r') as fp:
            count_lines = len(fp.readlines())
        return count_lines