Python 如何从ip2.txt获取Cisco备份脚本的密码、ip、启用密码和端口ssh
如何从ip2.txt获取Cisco备份脚本的密码、ip、启用密码和端口ssh? 大家好。我想为Cisco备份编写一个脚本。脚本将尝试通过ssh进行连接,如果失败,则通过telnet进行连接。连接的所有数据都将存储在ip2.txt文件中。各行内容如下: 192.168.1.12:管理员:密码:enpassword:22 为了测试,我使用了telnet连接,但我的字典不起作用。这样的错误是显而易见的- ip,用户,密码,启用密码,端口,=res[0]索引器:列表 索引超出范围Python 如何从ip2.txt获取Cisco备份脚本的密码、ip、启用密码和端口ssh,python,cisco-ios,Python,Cisco Ios,如何从ip2.txt获取Cisco备份脚本的密码、ip、启用密码和端口ssh? 大家好。我想为Cisco备份编写一个脚本。脚本将尝试通过ssh进行连接,如果失败,则通过telnet进行连接。连接的所有数据都将存储在ip2.txt文件中。各行内容如下: 192.168.1.12:管理员:密码:enpassword:22 为了测试,我使用了telnet连接,但我的字典不起作用。这样的错误是显而易见的- ip,用户,密码,启用密码,端口,=res[0]索引器:列表 索引超出范围 回答自动瓦迪姆,沙罗伊
回答自动瓦迪姆,沙罗伊金
now = datetime.datetime.now()
device_params={}
with open('ip2.txt', 'r') as f:
nums = f.read().splitlines()
for el in nums:
if el:
ip, user, password, enable_password, port, = el.replace(' ', '').split(":")
device_params = {
'device_type': 'cisco_ios',
'ip': ip,
'username': user,
'password': password,
'secret': enable_password,
'port': port
}
print(device_params)
now = datetime.datetime.now()
device_params={}
with open('ip2.txt', 'r') as f:
nums = f.read().splitlines()
for el in nums:
if el:
ip, user, password, enable_password, port, = el.replace(' ', '').split(":")
device_params = {
'device_type': 'cisco_ios',
'ip': ip,
'username': user,
'password': password,
'secret': enable_password,
'port': port
}
print(device_params)