Paramiko and Pexpect were skipped in their notes.
Because, they can all be replaced by Netmiko, do not want to waste too much time on them
Netmiko
Overall is still very simple, because the more humane
1 #!/usr/bin/env python 2 3 fromNetmikoImportConnecthandler4 5Pynet1 = {6 ' Device_type ':' Cisco_ios ',7 ' IP ':' 184.105.xx.xx ',8 ' username ':' Pyclass ',9 ' Password ':' ****** ',Ten} One AConn1 = Connecthandler (**PYNET1) -OUTP = Conn1.send_command ("Show Run | inc Logging ") - PrintOutp
It's just so easy to output.
Be aware of the two asterisks in the connecthandler brackets, which are marked with no less
- Use Dir () to explore a new library
>>>Dir (Netmiko) [' Connecthandler ',' Filetransfer ',' Netmikoauthenticationexception ',' Netmikotimeoutexception ',' Netmikoautherror ',' Netmikotimeouterror ',' Scpconn ',' __all__ ',' __builtins__ ',' __doc__ ',' __file__ ',' __name__ ',' __package__ ',' __path__ ',' __version__ ',' A10 ',' Alcatel ',' Arista ',' Avaya ',' Base_connection ',' brocade ',' Cisco ',' dell ',' Enterasys ',' Extreme ',' f5 ',' Fortinet ',' HP ',' Huawei ',' Juniper ',' Linux ',' Netmiko_globals ',' OvS ',' Paloalto ',' platforms ',' Quanta ',' Scp_handler ',' Ssh_connection ',' Ssh_dispatcher ',' Ssh_exception ']>>>
>>>Dir (Netmiko. Connecthandler) [' __call__ ',' __class__ ',' __closure__ ',' __code__ ',' __defaults__ ',' __delattr__ ',' __dict__ ',' __doc__ ',' __format__ ',' __get__ ',' __getattribute__ ',' __globals__ ',' __hash__ ',' __init__ ',' __module__ ',' __name__ ',' __new__ ',' __reduce__ ',' __reduce_ex__ ',' __repr__ ',' __setattr__ ',' __sizeof__ ',' __str__ ',' __subclasshook__ ',' Func_closure ',' Func_code ',' Func_defaults ',' Func_dict ',' Func_doc ',' Func_globals ',' Func_name ']>>>>>>
print conn1.find_prompt()
- Send_config_set ()
The command is in the form of an array pass in.
18 config_commands = [ ' logging buffered 19999 ' ] 19 OUTP = Conn1.send_ Config_set (config_commands) 20 print OUTP
- Connecting Juniper Devices
Take the SRX as an example
+ ASRX = { at ' Device_type ':' Juniper ', - ' IP ':' 184.105.xx.xx ', - ' username ':' Pyclass ', - ' Port ': A, - ' Password ':' ****** ', -} in -CONN2 = Connecthandler (**SRX) toOUTP = Conn2.send_command ("Show Arp") + PrintOutp - the PrintDir (conn2) * PrintDir (conn1)
Can see CONN1 conn2 These two connection namespaces are not quite the same
Take a look at Config_mode () and Check_config_mode ()
- Config_mode () and Check_config_mode ()
Check_config_mode () returns a Boolean value, true to indicate that the config mode is now
Config_mode () Enter Cofig mode
Exit_config_mode Exit Config mode
This is Juniper's commit.
conn2.commit()
?
The first glimpse of Netmiko