Just started to learn python, the power of the sensory function. Since the start is learning the network so familiar with the command line configuration of the router switch, so simply write a copy h3c interactive script. Because it is beginner, it only involves simple while loop and if condition judgment. Can be used as an interactive program of thought framework.
#!/usr/bin/env python__author__ = ' Administrator ' Print (' \ n ' + ' View-sys ', "\ n") While true: usr_view=input ("<Router>") if usr_view== "": Continue elif usr_view== ' quit ' or usr_view== ' qu ': quit () while usr_view== ' sys ' or usr_view== ' System-view ' and usr_view!= ' Quit ': sys_view=input (' [Router] ') if sys_view== "":continue elif sys_view== ' quit ' or sys_view== ' qu ': break while sys_view== ' INTERFACE&NBSP;E0/0/1 ' or sys_view== ' INT&NBSP;E0/0/1 ': &Nbsp;interface_view=input (' [ROUTER--ETHERNET0/0/1] ') if interface_view== "":continue elif interface_view== ' quit ' or interface_view== ' qu ': break else: print (' % unrecognized command ') else: print (' % unrecognized command ') else: print (' % unrecognized command ')
This article is from the "7070206" blog, please be sure to keep this source http://7080206.blog.51cto.com/7070206/1569177
An interactive script that uses Python to write an imitation router command