import paramiko from time import sleep

class HuaweiSwitch: def init(self, ip, username, password): self.ip = ip self.username = username self.password = password

def _get_connect(self):
    ssh_con = paramiko.SSHClient()
    ssh_con.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    ssh_con.connect(self.ip, username=self.username, password=self.password)
    self.cli = ssh_con.invoke_shell()
    self.cli.recv(65535)
    return ssh_con

def netconf(self):
    ssh_con = self._get_connect()
    commands = ['sys im\n', 'netconf\n', 'protocol inbound ssh port 830\n']
    for command in commands:
        self.cli.send(command)
        sleep(1)
        dis_this = self.cli.recv(65535).decode()
        print(dis_this)
    ssh_con.close()
    print('---使能Netconf成功---'
华为交换机使用python优化下面的命令使用其他方式import paramikofrom time import sleepclass HuaweiSwitch def __init__self ip username password selfip = ip selfusername = username selfpassword = passw

原文地址: https://www.cveoy.top/t/topic/fbTY 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录