'How to ignore annoying logs of terminal, using "session_log" in netmiko?

I want to find switches IP of model "MES3124". Suppose, I have switches in range from 192.168.10.74 to 192.168.10.254 and my solution works correct. But there is one switch (or more) with faulty fastethernet port and terminal constantly gives logs that prevent my parsing, because function stops at this switch and endlessly tries to parse it...

output.txt example

Switch with annoying logs

There is my code. A ConnectHandler with "session_log" in configuration trying to record logs of terminal that never end.

from netmiko import ConnectHandler;

mes = "MES3124";
file = "output.txt";
host = "";

def system_info_parser(target, config):
    command = "show system";
    with ConnectHandler(**config) as net_connect:
        output = net_connect.send_command(command);



    f = open(config["session_log"], 'r');
    for line in f:
        if target in line:
            return True;


# 10.74 - 10.253

if __name__ == '__main__':

    for i in range(74,254):
        host = "192.168.10." + str(i);
        config = {
            "device_type": "eltex",
            "host": host,
            "username": "someusername",
            "password": "somepassword",
            "session_log": file,
        };

        try:
            if system_info_parser(mes, config):
                print("found! " + host + ' has ' + mes);
                break;
        except:
            print("error, host was passed... " + '[' + host + ']');
            continue;

        print("checked... " + '[' + host + ']');

All my devices are eltex switches



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source