# 使用paramiko登录netconf from time import sleep import paramiko TERMINATOR = b']]>]]>' ip = '192.168.1.23' username = 'root' password = 'root!' new_msg = """<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="3"> <get-config> <source> <running/> </source> </get-config> </rpc> ]]>]]> """ def read(chan, responses=1): """Read responses.""" while responses: sleep(1) response = chan.recv(2048) yield response responses -= response.count(TERMINATOR) ssh_client = paramiko.SSHClient() ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh_client.connect(hostname=ip, username=username, password=password, port=830, timeout=300, look_for_keys=False) ssh_client.get_transport().set_keepalive(600) chan = ssh_client.get_transport().open_session() chan.invoke_subsystem('netconf') print(list(read(chan))) chan.sendall(new_msg.encode("utf-8")) print(list(read(chan))) chan.close()
使用paramiko登录netconf(2)
最新推荐文章于 2024-09-17 20:00:16 发布