python 路由器脚本
python scripts for router
我是初学者。我使用 paramiko 将配置推送到设备。我在 windows 机器上使用 anaconda。如何使用数据库和正确的格式来获取输出?请推荐一些关于异常处理的学习。
import paramiko
import sys
import subprocess
import time
vm = paramiko.SSHClient()
vm.set_missing_host_key_policy(paramiko.AutoAddPolicy())
vm.connect('x.x.x.x', username='your_user_name', password='your_password')
rtrlist = ["a","b"]
for n in rtrlist:
remote_conn_pre=paramiko.SSHClient()
remote_conn_pre.set_missing_host_key_policy(paramiko.AutoAddPolicy())
remote_conn_pre.connect(n, port=22, username='your_user_name', password='your_password', look_for_keys=False, allow_agent=False)
remote_conn.send("conf t\n")
time.sleep(.5)
output = remote_conn.recv(65535)
print (output)
remote_conn.send("flow exporter Netflow-Exporter-Mazu\n")
time.sleep(.5)
output = remote_conn.recv(65535)
print (output)
remote_conn.send("do wr\n")
time.sleep(.5)
output = remote_conn.recv(65535)
print (output)
vm.close()
使用了mongodb、pymongo、paramiko、get_transport()。
能够从数据库中选择数据。
能够晾干 运行 。在异常上几乎没有问题。总之,我能完成当前的任务。
我是初学者。我使用 paramiko 将配置推送到设备。我在 windows 机器上使用 anaconda。如何使用数据库和正确的格式来获取输出?请推荐一些关于异常处理的学习。
import paramiko
import sys
import subprocess
import time
vm = paramiko.SSHClient()
vm.set_missing_host_key_policy(paramiko.AutoAddPolicy())
vm.connect('x.x.x.x', username='your_user_name', password='your_password')
rtrlist = ["a","b"]
for n in rtrlist:
remote_conn_pre=paramiko.SSHClient()
remote_conn_pre.set_missing_host_key_policy(paramiko.AutoAddPolicy())
remote_conn_pre.connect(n, port=22, username='your_user_name', password='your_password', look_for_keys=False, allow_agent=False)
remote_conn.send("conf t\n")
time.sleep(.5)
output = remote_conn.recv(65535)
print (output)
remote_conn.send("flow exporter Netflow-Exporter-Mazu\n")
time.sleep(.5)
output = remote_conn.recv(65535)
print (output)
remote_conn.send("do wr\n")
time.sleep(.5)
output = remote_conn.recv(65535)
print (output)
vm.close()
使用了mongodb、pymongo、paramiko、get_transport()。 能够从数据库中选择数据。 能够晾干 运行 。在异常上几乎没有问题。总之,我能完成当前的任务。