telnet 登录执行命令linux

python 复制代码
from telnetlib import Telnet as telnet
from loguru import logger

__EXEC_END__ = "1002"


class TelnetCtr:
    __telnet__ = telnet()
    __user__ = None
    __passwd__ = None
    __Debug__ = None
    __timeout__ = None
    __record__ = tuple()
    __url__ = ""
    __port__ = 0

    def __init__(self, url: str, port: int, **kwargs):
        try:
            self.__url__ = url
            self.__port__ = port
            self.__record__ = kwargs
            self.__passwd__ = kwargs.pop("passwd", None)
            self.__user__ = kwargs.pop("user", None)
            self.__Debug__ = kwargs.pop("debug", None)
            self.__timeout__ = kwargs.pop("timeout", None)
            if self.__Debug__ is not None:
                self.__telnet__.set_debuglevel(self.__Debug__)
            if self.__timeout__ is not None:
                self.__telnet__.open(url, port, timeout=self.__timeout__)
            else:
                self.__telnet__.open(url, port)

            if self.__user__ is not None and self.__passwd__ is not None:
                self.__telnet__.read_until(b"login: ", timeout=self.__timeout__)
                self.__telnet__.write(
                    bytes(self.__user__.encode("utf-8") + "\r\n".encode("utf-8"))
                )
                self.__telnet__.read_until(b"Password: ", timeout=self.__timeout__)
                self.__telnet__.write(
                    bytes(self.__passwd__.encode("utf-8") + "\r\n".encode("utf-8"))
                )

        except SystemError as err:
            logger.error("TelnetCtrol: {}", err.args)

    # {"command":"except result"}
    def command(self, cmd: list) -> dict:
        res = {}
        try:
            for it in cmd:
                self.__telnet__.write(
                    bytes(
                        it.encode("utf-8")
                        + "&& echo EXEC END $((1000+2)) \
                           || echo EXEC END $((1000+2))".encode(
                            "utf-8"
                        )
                        + "\r\n".encode("utf-8")
                    )
                )
                res[it] = self.__telnet__.read_until(
                    "EXEC END 1002".encode("utf-8"), timeout=30
                ).decode("utf-8")

        except SystemError as e:
            logger.error("telnet system error:{}".format(e.args))
        return res

QT 显示 Matplot 的绘画图,位置怎么确定,可以自己构建 ,QT 组件,然后随意拖拽,就可以在自己的UI 界面中随意显示
需要做类的提升
参考这篇博文
https://blog.csdn.net/g11023225/article/details/119274622
绘图 类的模块应用,感谢 github丰富的 代码

python 复制代码
from PyQt5.QtWidgets import*
from matplotlib.backends.backend_qt5agg import FigureCanvas
from matplotlib.figure import Figure

# TODO: MORE SUB PLOT NEED ADD
class matplot(QWidget):
    def __init__(self, parent = None):
        QWidget.__init__(self, parent)        
        self.canvas = FigureCanvas(Figure())
        vertical_layout = QVBoxLayout()
        vertical_layout.addWidget(self.canvas)        
        self.canvas.axes = self.canvas.figure.add_subplot(111)
        self.setLayout(vertical_layout)

可以在 desigin 中 进行拖拽,复制模块儿

相关推荐
驭渊的小故事14 分钟前
linux 基础命令 + git 仓库创建和配置命令
linux·git
ShineWinsu36 分钟前
对于Redis:主从复制的解析
linux·数据库·c++·redis·缓存·面试·主从复制
Lsetea37 分钟前
OpenSSL verify报unable to get issuer certificate:error 2与partial_chain排查
linux·https·ssl证书·openssl·证书链
许彰午1 小时前
03-Linux环境准备依赖包内核参数与用户组
linux·运维·服务器·数据库
阳光九叶草LXGZXJ1 小时前
达梦数据库-报错-16-MERGE INTO提示:无效的列名[XX]
linux·运维·数据库·sql·学习
CarIise1 小时前
Java实训阶段查漏补缺复习笔记2
java·linux·算法
一号弯2 小时前
Hyperv的LINUX虚拟机扩容
linux·运维·服务器
缘友一世2 小时前
银河护卫队在steam(linux Proton GE-Proton10-34)上启动无窗口问题修复
linux·ubuntu·steam·proton
一条大祥脚2 小时前
【CS336】lecture4 MoE|负载均衡|MoE并行|训练稳定性|Deepseek回顾
运维·负载均衡
wunaiqiezixin2 小时前
MIT 6.S081 util 实验篇(lab1):primes (moderate/hard)
linux·unix·os·xv6·mit6.s081