#!/usr/bin/env python
from netmiko import Netmiko
from getpass import getpass
import sys
import json
passwd = getpass()
command1 = "show system info"
command2 = "show version active"
with open("./list_UC_test.txt") as fileA:
# Use fileA to refer to the file object
Targets = fileA.readlines()
print (Targets)
for node in Targets:
PA = {
"host": node.strip(),
"username":"admin",
"password":passwd,
"device_type":"paloalto_panos",
}
print (PA)
net_connect = Netmiko(**PA)
print("Trying to Connect...")
print(net_connect.find_prompt()) # 显示出 命令行的输出
# 解决SSh-key acceptance的问题
output = net_connect.send_command_timing("copy bootflash://sup-active/init.log scp://admin@1.2.3.4/repo vrf mgmt"
if 'Are you sure you want to continue connecting' in output:
output += net_connect.send_command_timing("yes")
if 'password' in output:
output += net_connect.send_command_timing(password)
print("Connected Now")
output = net_connect.send_command(command1, use_textfsm=True)
print (json.dumps(output, indent=4))
# if "cuc" in node:
# print ("matched cuc as %s \n Call Mgr cert remove command will be sent " % (node))
# net_connect.send_command_timing(command2) #send_command_timing 用于short running command,not checking prompt
net_connect.disconnect()
print()
output = net_connect.send_command_timing("vpn-sessiondb logoff ipaddress 10.1.2.2")
if 'Do you want to' in output:
output += net_connect.send_command_timing("y")
:param normalize: Ensure the proper enter is sent at end of command (default: True). :type normalize: bool