import paramiko
# SSH连接配置
hostname = "172.16.13.122"
username = "root"
password = "Hnrs@2023"
# 创建SSH客户端
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
# 连接服务器
client.connect(hostname, username=username, password=password)
# 执行命令
command = "smidump -f python -k SANGFOR-GENERAL-MIB.mib > output.py"
stdin, stdout, stderr = client.exec_command(command)
# 获取命令执行结果
output = stdout.read().decode("utf-8")
error = stderr.read().decode("utf-8")
if error:
print(f"命令执行失败:{error}")
else:
# 处理output,比如保存为文件
with open("output.py", "w") as f:
f.write(output)
finally:
# 关闭SSH连接
client.close()
上一篇
python生产消费者线程
python生产消费者线程
2020-02-18
下一篇
python通过 websocket建立链接的方法
通过websocket建立链接
2020-02-18