前提~实验准备:先配置SSH
虚拟机:
[~]# pip3.8 install netmiko
[~]# python3.8
>>> import netmiko
思科模拟器:
SW2# show run int loop1 #查看是否有loop1地址,若有则删除
SW2# no int loop1 #删除loop1
虚拟机;
[~]# touch ssh_Natmiko.py #首先创建一个py文件,名称随意
[~]# vim ssh_Natmiko.py #脚本文件 插入如下内容
from netmiko import ConnectHandler
import paramiko
SW2 = {
'device_type': 'cisco_ios',
'ip': '192.168.88.100',
'username': 'python',
'password': '123'
}
connect = ConnectHandler(**SW2)
print("Successfully connected to " + SW2['ip'])
config_commands = ['int loop 1', 'ip address 2.2.2.2 255.255.255.255']
output = connect.send_config_set(config_commands)
print(output)
result = connect.send_command('show run int loop 1')
print(result)
[~]# python3.8 ssh_Natmiko #虚拟机运行该脚本文件
#运行成功后:
思科模拟器:
SW2:show ip int brief #查看各接口地址(完)