Last active
March 24, 2021 07:41
-
-
Save YMont/681f25fbbf2434030e361df920982362 to your computer and use it in GitHub Desktop.
netmiko-basic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import netmiko #帶入模組 | |
from netmiko import ConnectHandler #將Netmiko模組的ConnectHandler連線函式帶入 | |
def speed_change(param): #函式定義 | |
print("Please wait seconds. Connecting … \n") #作為等待過程 | |
my_device = { #利用Python字典對應的鍵與值代入路由器 | |
"host": "xxx.xxx.xxx.xxx", #輸入路由器的IP Address | |
"username": "xxx", #輸入使用者名稱 | |
"password": "xxx", #輸入密碼 | |
"device_type": "cisco_ios"} #輸入路由器的IOS type | |
net_connect = ConnectHandler(**my_device) #運用Python(**kargs) | |
cmd_1 = "show ip int brief" #指令1 | |
cmd_2 = "interface fastEthernet 0/0", | |
"duplex auto", | |
"speed %s"%param #指令2 #%s%param-利用變數代入 | |
output_1 = net_connect.send_command(cmd_1) #輸出命令1 | |
output_2 = net_connect.send_config_set(cmd_2) #輸出命令2 | |
print(output_1) #印出結果1 | |
print("-"*50) | |
print(output_2) #印出結果2 | |
net_connect.disconnect() #連線結束 | |
speed_change(input("Please key in your speed parameter 10/100/auto:")) #呼叫speed_change函式,並且讓使用者可以輸入想寫入的參數 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment