<gh_stars>10-100
import paramiko
import time


class CiscoSSH:
    def __init__(self, ip, username, password, enable, disable_paging=True):
        print("Метод __init__")
        client = paramiko.SSHClient()
        client.set_missing_host_key_policy(paramiko.AutoAddPolicy())

        client.connect(
            hostname=ip,
            username=username,
            password=password,
            look_for_keys=False,
            allow_agent=False,
        )

        self.ssh = client.invoke_shell()
        self.ssh.send("enable\n")
        self.ssh.send(enable + "\n")
        if disable_paging:
            self.ssh.send("terminal length 0\n")
        time.sleep(1)
        self.ssh.recv(1000)

    def __enter__(self):
        print("Метод __enter__")
        return self

    def __exit__(self, exc_type, exc_value, traceback):
        print("Метод __exit__")
        self.ssh.close()

    def send_show_command(self, command):
        self.ssh.send(command + "\n")
        time.sleep(2)
        result = self.ssh.recv(5000).decode("ascii")
        return result


with CiscoSSH("192.168.100.1", "cisco", "cisco", "cisco") as r1:
    print(r1.send_show_command("sh clock"))

import paramiko
import time


class CiscoSSH:
    def __init__(self, ip, username, password, enable, disable_paging=True):
        print("Метод __init__")
        client = paramiko.SSHClient()
        client.set_missing_host_key_policy(paramiko.AutoAddPolicy())

        client.connect(
            hostname=ip,
            username=username,
            password=password,
            look_for_keys=False,
            allow_agent=False,
        )

        self.ssh = client.invoke_shell()
        self.ssh.send("enable\n")
        self.ssh.send(enable + "\n")
        if disable_paging:
            self.ssh.send("terminal length 0\n")
        time.sleep(1)
        self.ssh.recv(1000)

    def __enter__(self):
        print("Метод __enter__")
        return self

    def __exit__(self, exc_type, exc_value, traceback):
        print("Метод __exit__")
        self.ssh.close()

    def send_show_command(self, command):
        self.ssh.send(command + "\n")
        time.sleep(2)
        result = self.ssh.recv(5000).decode("ascii")
        return result


with CiscoSSH("192.168.100.1", "cisco", "cisco", "cisco") as r1:
    print(r1.send_show_command("sh clock"))