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 中 进行拖拽,复制模块儿

相关推荐
心灵彼岸-诗和远方12 分钟前
DevOps业务价值流:架构设计最佳实践
运维·产品经理·devops
一只哒布刘17 分钟前
NFS服务器
运维·服务器
苹果醋31 小时前
Java8->Java19的初步探索
java·运维·spring boot·mysql·nginx
二十雨辰1 小时前
[linux]docker基础
linux·运维·docker
Jason-河山2 小时前
【自动化更新,让商品信息跳舞】——利用API返回值的幽默编程之旅
运维·自动化
饮浊酒2 小时前
Linux操作系统 ------(3.文本编译器Vim)
linux·vim
lihuhelihu2 小时前
第3章 CentOS系统管理
linux·运维·服务器·计算机网络·ubuntu·centos·云计算
哲讯智能科技2 小时前
SAP Business One市场价格解析
运维·sap·erp
矛取矛求2 小时前
Linux系统性能调优技巧
linux
山东布谷科技官方2 小时前
布谷直播源码部署服务器关于数据库配置的详细说明
运维·服务器·数据库·直播系统源码·直播源码·直播系统搭建·直播软件开发