Sei sulla pagina 1di 11

Learn Python Now!

CCIE & CCSI: Yasser Ramzy Auda

I would like to explain my journey with learning python and what is the best resources and tools
to learn python.

First why learning python programming language?


Python is a widely used high-level programming language used for general-purpose
programming, created by Guido van Rossum and first released in 1991. An interpreted language.

 Python so far is the best programming language for Networking automation and
security.
 Python is one of the best languages to be used in digital forensics.
 Python is the preferred programming language for creating small and effective hacking
tools , including in exploit development.
 Python is the best language to start learning IoT Internet of Things programming using
boards like Raspberry Pi & Arduino.
 Python can serve as a scripting language for web applications.
 Python has been successfully embedded in many software products as a scripting
language, Including animation packages such as 3ds Max, Blender, Cinema 4D, , Maya.

 Python is also used in algorithmic trading and quantitative finance.


 Python has been used in artificial intelligence tasks.
 Python is often used for natural language processing tasks.

 Large organizations that make use of Python include Wikipedia, Google,Yahoo!, CERN,
NASA,YouTube and some smaller entities like ILM,and ITA. The social news networking
site Reddit is written entirely in Python.

Still not sure why learn Python? ……ok python is one of the real players in SDN.

Why Python for SDN?


First off, you may be asking, "Why Python for SDN?" There are plenty of other languages to
choose from. Three basic reasons:

It's an easy language to learn. Granted it will take a lot of additional work to master it, but
getting started is easy.
It's general purpose. With Python, you can do everything from gathering data to scripting
configuration changes to playing games.
It's widely supported. Python seems to be the language of choice for most SDN vendors.

SDN has come a long way over the years. If you've been following it at all, I'm sure you're just as
amazed as I am at how much it has matured. The problem is the feature set and standardization
needed for widespread adoption isn't quite there yet. Until we get those features, SDN is
effectively contained to the world of the data center.

Nearly every major SDN vendor offers a Python API or software developer's kit for their product.
If you're an engineer skilled with coding in Python, your imagination is the limit on what you can
start doing with the products.
Source:techtarget.com

1
Learn Python Now! CCIE & CCSI: Yasser Ramzy Auda

If you are not familiar with SDN concept, I wrote pdf in 31 pages about it, you can download it
for free from the following link:
https://learningnetwork.cisco.com/docs/DOC-30978

"REST or RESTful APIs or libraries that use languages like Python, for example, enable you to
write the kinds of scripts that provision and configure networks at wide scale,"
https://pythontips.com/2013/08/06/python-socket-network-programming/

Now let’s talk how I learned python

My Programming historical background


(You can skip this part if you do not have time unless you want to know how I learned python in
two weeks)

First of all I am familiar with programming basic concepts since I grow up in University few
decades ago with procedural programming language such as Fortran, ALGOL, COBOL BASIC and
Pascal.
Then end of 90s I learned Visual Basic 5.0 was derived from BASIC and declared legacy in 2008.

I stopped working with programming till 2015 , during all that time I just learned HTML 4.01 &
CSS2 , precisely in 2007.

In 2015 SDN is knocking the doors of IT networking engineers and developers plus
Network/system engineers will work in same new department ( DevOP Dept)……sooner or
later companies will hire person with both programming and networking skills …..At least.

I start with Java and reached a good point on it but then I became busy in business so I stopped
learning Java.

In 2016 I involved with many IT security projects and I saw python doing great job so I decide to
study it once I have time, and I did.

2
Learn Python Now! CCIE & CCSI: Yasser Ramzy Auda

Resources I used to learn Python:

First you need to refresh your mind with basic programming concepts since programming
languages are Object-oriented programming nowadays, no more procedural programming
language, actually in python everything is object.

So you should have a sold Foundations of Programming, try to watch this CBT series called
Foundations of Programming: Fundamentals
https://www.lynda.com/Programming-Foundations-tutorials/Foundations-Programming-
Fundamentals/83603-2.html
By instructor Simon Allardice

Now time to study python, first let’s learn it by example, to do so use the following free website
https://www.codecademy.com/learn/python

Worth to mention you can also try https://checkio.org

Ok you learned something here, now you know what variables, strings, lists, integers are.

Now time to watch some other videos; choose one of the following CBT series :
Lynda Python Essential Training
https://www.lynda.com/Python-3-tutorials/essential-training/62226-2.html

ITpro TV Python Programming


https://itpro.tv/course-library/python-programming/overview70717/

LiveLessons Python Fundamentals


http://www.informit.com/store/python-fundamentals-livelessons-video-training-
9780137143412

Or just learn it for free


https://www.coursera.org/learn/python
By Associate Professor Charles Severance from University of Michigan

Also you can give a look to Python free courses from sololearn.com and cybrary.it

During watching videos you will learn that you should set your machine with python by
downloading it from
https://www.python.org/downloads/

Take care, you have two main versions, python 2 and python 3 and there is some critical
differences between both when writing codes syntax.
Check the differences in this link :
http://sebastianraschka.com/Articles/2014_python_2_3_key_diff.html

3
Learn Python Now! CCIE & CCSI: Yasser Ramzy Auda

Also you will notice that you must set your OS and editing the PATH environment variable for
Python
Check this link to know how to do it
http://stackoverflow.com/questions/3701646/how-to-add-to-the-pythonpath-in-windows-7

One of the other tools you can use is notepad++ , download for from here for free:
https://notepad-plus-plus.org/download/v7.3.1.html
also you can add python plug in to it , http://npppythonscript.sourceforge.net/download.shtml

Finally as any programmer and as with any programming language, you will need IDE .

An integrated development environment (IDE) is a software application that provides


comprehensive facilities to computer programmers for software development. An IDE normally
consists of a source code editor, build automation tools and a debugger.

Different free and commercial IDEs available for each programming language, I prefer you
download one of the following for python:

Geany
https://www.geany.org/Download/Releases

PyCharm
https://www.jetbrains.com/pycharm-edu/download/

Time to read some books (one or two is enough), check the following list:
 Head First Python, 2nd Edition -Publisher: Oreilly
 Python Crash Course -Publisher: No Starch Press
 Python Programming Introduction -Publisher: Logical Operations

There is a good book summarizing Python commands in less than 200 pages:
 The Python Quick Syntax Reference -Publisher: Apress

End of this point you should learned the following topics about python :
Variables, Simple Data Types, Lists, if Statements, Dictionaries, Functions, Classes, OS File system
accessing, Errors Handling/Exceptions, User Input and while Loops .

Now you should learn advanced topic which actually made you decide learning Python:

How to create GUI for python scripts using Python Tkinter (to create GUI)
http://www.python-course.eu/python_tkinter.php
remember Tkinter can be installed when you installed Python from the beginning.

How to use python for web applications and databases .

Note: To create executable .exe file from a Python .py script (py2exe work with python2 only)
http://www.py2exe.org/

4
Learn Python Now! CCIE & CCSI: Yasser Ramzy Auda

How to use python for networking


This important part, you should learn socket programming which is a standards concept with
any programming language means how to use your programming skills to create networking
applications

This book was good for me in that part, specially first 5 chapters
 Foundation of Python Network Programming -Publisher: Apress

You will learn server , client and general socket methods ,how to create TCP and UDP server
clients py files and make two machines create TCP connection for instance using one python
script on each machine....etc.

How to use python for Security


Another important part, read one of the following books

 Python Penetration Testing Essentials chapter -Publisher: Apress


 Black Hat Python -Publisher: No Starch Press
 Violent Python: A Cookbook for Hackers, Forensic Analysts, Penetration Testers and
Security Engineers -Publisher: SYNGRESS (preferred by SANS for their python
certification)
 Beginning Ethical Hacking with Python -Publisher: Packt Publishing (chapter 22,23,24
only )

Also there are some videos around of you wanting to such as Python for Pentesters
http://www.pentesteracademy.com/course?id=1

And do not forget that SANS just released a certification for Python
https://www.sans.org/press/announcement/2016/05/09/1
https://www.sans.org/course/python-for-pen-testers

5
Learn Python Now! CCIE & CCSI: Yasser Ramzy Auda

Tips and Examples


We are Network and security engineers, we should start learning python from first day using
networking and security concepts in mind and look to every term we learn in Python with
Networking Engineer Perspective

For example in the below picture, I tried to learn Else IF (else command)
By creating a code will print cisco show run command if I am not using Juniper or Hawaii while
if I am not using cisco it will display the current router configuration depending to vendor name I
am going to type .

By the way above is good example for how Python3 is different than python 2.7, if we using
python 2.7 I should use raw_input () function instead of input() , as below

6
Learn Python Now! CCIE & CCSI: Yasser Ramzy Auda

So This is how you should teach yourself python, not by using examples such as type your
favorite color or what is your pet name .

Another example, when you learn [list] in python, what about apply the similar concept in Cisco
Routers and create a list shows the different options when configuring duplex under interfaces.

Another example when we learn [else if] command, we can apply it to cisco world such as
following example , I used python2.7 here.

To verify it, I execute this code and hub was in my answer it will warn me that speed should be
auto

If router was in my answer it and I choose 10mb it will warn me that speed should be auto

If router was in my answer it and I choose auto, it will tell me my setting is acceptable

Something else worth to be in mind , make sure that modules you need is already installed ,
generally in networking we need modules such as OS , SOCKET .
Check for complete list here in Python Package Index:
https://pypi.python.org/pypi

7
Learn Python Now! CCIE & CCSI: Yasser Ramzy Auda

Simple example shows resolving website address with two lines, I own that website so no issue

In Security we have a lot of modules such as NMAP


https://pypi.python.org/pypi/python-nmap

To practice nmap check the [usage] part in the following link by the author of nmap module for
python
http://xael.org/pages/python-nmap-en.html

Here is an example for nmap in python


I removed my default gateway FQDN for my privacy, but still picture below provide good
example for how to use nmap in python

8
Learn Python Now! CCIE & CCSI: Yasser Ramzy Auda

Another example, script doing ping for network address

Here is another example, you will need to install Exscript first which is a Python module making
Telnet and SSH easy, install it from https://github.com/knipknap/exscript
We will SSH into a Cisco device, run "show ip route", display the results in notepad, then end the
script.

from Exscript.util.interact import read_login


from Exscript.protocols import SSH2

account = read_login()
conn = SSH2()
conn.connect('192.168.1.11')
conn.login(account)

conn.execute('show ip route')
print conn.response

conn.send('exit\r')
conn.close()

More details can be found here:


https://github.com/knipknap/exscript/wiki/Python-API-Tutorial

9
Learn Python Now! CCIE & CCSI: Yasser Ramzy Auda

Python and Cisco Resources


How to use NAPALM (Python library) to Manage IOS Devices
http://networktocode.com/labs/tutorials/how-to-use-napalm-python-library-to-manage-ios-
devices/

Using Python to script Cisco routers


https://communities.cisco.com/people/franklaszlo/blog/2016/04/03/using-python-to-script-
cisco-routers

Automating Cisco IOS


https://pynet.twb-tech.com/blog/automation/cisco-ios.html

Python for Network Engineers


https://pynet.twb-tech.com/

Cisco Nexus 9000 Series NX-OS Programmability with Python API


http://www.cisco.com/c/en/us/td/docs/switches/datacenter/nexus9000/sw/6-
x/programmability/guide/b_Cisco_Nexus_9000_Series_NX-
OS_Programmability_Guide/b_Cisco_Nexus_9000_Series_NX-
OS_Programmability_Guide_chapter_0100.html

Control Cisco VIRL through a python script


https://pypi.python.org/pypi/python-virl/1.0.1

General Resources:
Stack Overflow is a community of 6.6 million programmers
http://stackoverflow.com/questions/tagged/python
http://stackoverflow.com/documentation/python/topics

Python Modules
https://www.tutorialspoint.com/python/python_modules.htm

Useful Python Modules


https://wiki.python.org/moin/UsefulModules

Regular expression operations (re module)


https://docs.python.org/2/library/re.html

Errors and Exception


https://docs.python.org/2.7/tutorial/errors.html
https://docs.python.org/2/library/exceptions.html

Python cheat sheet


https://ehmatthes.github.io/pcc/cheatsheets/README.html
https://perso.limsi.fr/pointal/_media/python:cours:mementopython3-english.pd
www.cogsci.rpi.edu/~destem/igd/python_cheat_sheet.pdf
http://www.pythonforbeginners.com/cheatsheet/python-cheat-sheets
https://www.cheatography.com/davechild/cheat-sheets/python/

10
Learn Python Now! CCIE & CCSI: Yasser Ramzy Auda

Good Luck
CCIE & CCSI: Yasser Auda
https://www.facebook.com/YasserRamzyAuda
https://learningnetwork.cisco.com/people/yasserramzy
https://www.youtube.com/user/yasserramzyauda

11

Potrebbero piacerti anche