环境背景
python3.8,华为交换机 每次手动登录交换机再进行绑定操作,太过机械化啊,本着懒人原则,写一个脚本真不是事情
脚本
from netmiko import ConnectHandler
import time
def bing_mac(mac):
sw_ip = '10.10.10.10' #交换机ip
username = 'admin' #交换机账号
password = 'xxxxxx' #交换机密码
type = 'huawei' #交换机类型,具体需要根据netmiko支持的类型去填
device = ConnectHandler(device_type=type, ip=sw_ip, username=username, password=password)
print('已连接上%s' % sw_ip)
output= device.send_command('sys',expect_string = ']')
print(output)
time.sleep(1)
cmd2= 'user-bind static mac-address %s '%(mac)
output=device.send_command(cmd2,expect_string = ']')
print(output)
time.sleep(2)
print('已绑定:%s' % output)
cmd4='quit'
output = device.send_command(cmd4, expect_string='>')
print(output)
device.disconnect()
if __name__ == '__main__':
print('正在绑定mac')
mac = '088F-C3E3-F602'
bing_mac(mac)
print('mac已绑定成功')
标签:netmiko,python,ip,device,mac,交换机,print,output
From: https://blog.51cto.com/bomby/7134460