Learn Python Now PDF
Learn Python Now PDF
Learn Python Now PDF
I would like to explain my journey with learning python and what is the best resources and tools
to learn python.
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.
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.
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/
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
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
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
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 .
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.
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
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.
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
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
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
8
Learn Python Now! CCIE & CCSI: Yasser Ramzy Auda
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.
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()
9
Learn Python Now! CCIE & CCSI: Yasser Ramzy Auda
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
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