Python For Network Engineers 1
Python For Network Engineers 1
(1) Network programmability made easy
Router-1
- Basic configuration
- config terminal
- hostname R1
- Configure IP interface
- interface gig0/0
- ip address 192.168.122.71 255.255.255.0
- no shut
- Enable remote management access (Telnet)
- enable password cisco
- username admin password cisco
- line vty 0 4
- login local
- transport input all
- Debugging
- debug telnet
Ubuntu-1
- Test internet connectivity
- ping google.com = [OK]
- Update references in Ubuntu
- apt-get update
- > Downloads the package lists from the repositories and “updates” them to get information on the newest versions of packages and their dependencies.
- > It will do this for all repositories and PPAs
- apt-get update
- Install Python 2.7.X
- apt-get install python
- Enter python shell
- python
- quit()
- > To quit python shell
- Create Python script
- nano pythonR1
- Paste the Python 2.7.X Telnet Example (Figure 2)
- Modified as necessary (Figure 3)
- Run Python script
- python pythonR1 (Figure 4)
- Enter username: admin
- Enter password: cisco
- It will also print all the commands that we send to the router
- Router debug output (Figure 5)
(2) Remove enable password and improve script
Router-1
- Add privilege level 15 to the “python” user
- user python privilege 15 password cisco
Ubuntu-1
- Use Python script file extension (Figure 1)
- cp pythonR1 S1script2.py
- nano S1script2.py
- Notice there is text color (because of the extension)
- The “#!” indicates which interpreter to use, in this case python
- Run the script without command “python”
- S1script2.py
- >bash: command not found
- chmod +x ./S1script2.py
- > To change the permission on the script, to make it executable
- ./S1script2.py
- > Now the script is able to run
- > “./” is to call a file in the local directory
- S1script2.py
- Remove the enable password steps (Figure 2)
- nano S1script2.py
- ./S1script2.py
- > Use “python” username
0 Comments