SlideShare una empresa de Scribd logo
1 de 17
Descargar para leer sin conexión
Introduction to Python
for Network Engineer
(Basic)
Before We Start
Do you know these following languages?
´  C/C++
´  Java
´  Shell
´  Batch
´  TCL
´  Python
Python Overview
´  A script programming language
´  A high-level programming language 
´  object-oriented
´  No compilation
´  No datatype declaration
What can Python do?
Many many things which Python could do
but the only one thing we will talk about is
“ Network Automation”
Running Python: Interactively
Python is pre-installed on Linux platform
[porhai@python ~]$ python
Python 2.6.6 (r266:84292, Jul 23 2015, 15:22:56)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> print "Hello world"
Hello world
>>>
Running Python: .py file
[porhai@python ~]$ vi khnog.py
print "hello world"
~
~
[porhai@python ~]$ python khnog.py
hello world
[porhai@python ~]$
Python VS Shell
[porhai@python ~]$ echo Hello World
Hello World
[porhai@python ~]$
>>> print "Hello world"
Hello world
>>>
Shell
Python
Python VS Shell
[porhai@python ~]$ vi khnog.sh
echo Hello World
~
[porhai@python ~]$ sh khnog.sh
Hello World
[porhai@python ~]$
Shell Python
[porhai@python ~]$ vi khnog.py
print "hello world"
~
[porhai@python ~]$ python khnog.py
hello world
[porhai@python ~]$
Python Input/Output
>>> x = raw_input("x = ")
x = 123
>>>
>>> print x
123
Python Datatypes
´  Integer (int)
´  Float (float)
´  String (str)
´  List (list)
´  Dictionary (dict)
>>> x=1
>>> type(x)
<type 'int'>
>>> x="hello"
>>> type(x)
<type 'str'>
>>>
>>> x=[1,2,3]
>>> type(x)
<type 'list'>
>>> x={'name':'porhai', 'age':22}
>>> type(x)
<type 'dict'>
>>> x=1.1
>>> type(x)
<type 'float'>
Python Modules
´  Telnetlib
´  Paramiko
´  Smtplib
´  PySNMP
Python Program Example
´  Login to Switch
´  Enter Username and Password
´  Get configuration of interface
´  Output result
Python Code
[porhai@python ~]$ vi khnog.py
import telnetlib
def open_telnet_conn(ip):
#Change exception message
try:
#Define telnet parameters
username = 'porhai'
password = 'porhai'
TELNET_PORT = 23
#Logging into device
connection = telnetlib.Telnet(ip, TELNET_PORT, TELNET_TIMEOUT)
Python Code
connection.write(username + "n")
connection.write(password + "n")
time.sleep(1)
connection.write("show run int g0/1 n")
time.sleep(1)
Output = connection.read_very_eager()
print Output
#Closing the connection
connection.close()
except IOError:
print "Input parameter error! Please check username, password
and file name."
open_telnet_conn("10.1.1.1")
Python Program Executed
[porhai@python ~]$ python khnog.py
User Access Verification
Username: porhai
Password:
S1#show run int g0/1
Building configuration...
Current configuration : 66 bytes
!
interface GigabitEthernet0/1
no switchport
no ip address
end
Reference
´  Python Language Comparison
https://www.python.org/doc/essays/comparisons/
Shell
´  Python Lesson
http://learnpythonthehardway.org/
´  Python for Network Engineers
https://pynet.twb-tech.com/
Thanks you!!!

Más contenido relacionado

La actualidad más candente

Compact ordered dict__k_lab_meeting_
Compact ordered dict__k_lab_meeting_Compact ordered dict__k_lab_meeting_
Compact ordered dict__k_lab_meeting_miki koganei
 
Swift 4 : Codable
Swift 4 : CodableSwift 4 : Codable
Swift 4 : CodableSeongGyu Jo
 
Wildcards, Simple Shell Programs and Shell Variables
Wildcards, Simple Shell Programs and Shell VariablesWildcards, Simple Shell Programs and Shell Variables
Wildcards, Simple Shell Programs and Shell VariablesGaurav Bisht
 
Natural Language Processing and Python
Natural Language Processing and PythonNatural Language Processing and Python
Natural Language Processing and Pythonanntp
 
Happy Go Programming
Happy Go ProgrammingHappy Go Programming
Happy Go ProgrammingLin Yo-An
 
The Ring programming language version 1.7 book - Part 14 of 196
The Ring programming language version 1.7 book - Part 14 of 196The Ring programming language version 1.7 book - Part 14 of 196
The Ring programming language version 1.7 book - Part 14 of 196Mahmoud Samir Fayed
 
Pipes and filters
Pipes and filtersPipes and filters
Pipes and filtersbhatvijetha
 
Vim Script Programming
Vim Script ProgrammingVim Script Programming
Vim Script ProgrammingLin Yo-An
 
Programming Under Linux In Python
Programming Under Linux In PythonProgramming Under Linux In Python
Programming Under Linux In PythonMarwan Osman
 
Briefly Rust - Daniele Esposti - Codemotion Rome 2017
Briefly Rust - Daniele Esposti - Codemotion Rome 2017Briefly Rust - Daniele Esposti - Codemotion Rome 2017
Briefly Rust - Daniele Esposti - Codemotion Rome 2017Codemotion
 

La actualidad más candente (20)

Compact ordered dict__k_lab_meeting_
Compact ordered dict__k_lab_meeting_Compact ordered dict__k_lab_meeting_
Compact ordered dict__k_lab_meeting_
 
Cpp lab 13_pres
Cpp lab 13_presCpp lab 13_pres
Cpp lab 13_pres
 
Python for Penetration testers
Python for Penetration testersPython for Penetration testers
Python for Penetration testers
 
Swift 4 : Codable
Swift 4 : CodableSwift 4 : Codable
Swift 4 : Codable
 
Crystal Rocks
Crystal RocksCrystal Rocks
Crystal Rocks
 
Wildcards, Simple Shell Programs and Shell Variables
Wildcards, Simple Shell Programs and Shell VariablesWildcards, Simple Shell Programs and Shell Variables
Wildcards, Simple Shell Programs and Shell Variables
 
Python build your security tools.pdf
Python build your security tools.pdfPython build your security tools.pdf
Python build your security tools.pdf
 
Natural Language Processing and Python
Natural Language Processing and PythonNatural Language Processing and Python
Natural Language Processing and Python
 
Happy Go Programming
Happy Go ProgrammingHappy Go Programming
Happy Go Programming
 
The Ring programming language version 1.7 book - Part 14 of 196
The Ring programming language version 1.7 book - Part 14 of 196The Ring programming language version 1.7 book - Part 14 of 196
The Ring programming language version 1.7 book - Part 14 of 196
 
Swift Study #7
Swift Study #7Swift Study #7
Swift Study #7
 
Unix - Shell Scripts
Unix - Shell ScriptsUnix - Shell Scripts
Unix - Shell Scripts
 
Clojure+ClojureScript Webapps
Clojure+ClojureScript WebappsClojure+ClojureScript Webapps
Clojure+ClojureScript Webapps
 
Basics of unix
Basics of unixBasics of unix
Basics of unix
 
Biopython
BiopythonBiopython
Biopython
 
Pipes and filters
Pipes and filtersPipes and filters
Pipes and filters
 
Vim Script Programming
Vim Script ProgrammingVim Script Programming
Vim Script Programming
 
Programming Under Linux In Python
Programming Under Linux In PythonProgramming Under Linux In Python
Programming Under Linux In Python
 
Briefly Rust - Daniele Esposti - Codemotion Rome 2017
Briefly Rust - Daniele Esposti - Codemotion Rome 2017Briefly Rust - Daniele Esposti - Codemotion Rome 2017
Briefly Rust - Daniele Esposti - Codemotion Rome 2017
 
Workshop programs
Workshop programsWorkshop programs
Workshop programs
 

Destacado

Rapid Ring Protection Protocol (RRPP)
Rapid Ring Protection Protocol (RRPP)Rapid Ring Protection Protocol (RRPP)
Rapid Ring Protection Protocol (RRPP)KHNOG
 
Understanding REST APIs in 5 Simple Steps
Understanding REST APIs in 5 Simple StepsUnderstanding REST APIs in 5 Simple Steps
Understanding REST APIs in 5 Simple StepsTessa Mero
 
Bidirectional Forwarding Detection (BFD)
Bidirectional Forwarding Detection (BFD) Bidirectional Forwarding Detection (BFD)
Bidirectional Forwarding Detection (BFD) KHNOG
 
Network Mapper (NMAP)
Network Mapper (NMAP)Network Mapper (NMAP)
Network Mapper (NMAP)KHNOG
 
Policy Based Routing (PBR)
Policy Based Routing (PBR)Policy Based Routing (PBR)
Policy Based Routing (PBR)KHNOG
 
Routing Implementation - Cisco vs. Mikrotik
Routing Implementation - Cisco vs. MikrotikRouting Implementation - Cisco vs. Mikrotik
Routing Implementation - Cisco vs. MikrotikKHNOG
 
IT Service Level Agreement
IT Service Level AgreementIT Service Level Agreement
IT Service Level AgreementKHNOG
 
SIP (Session Initiation Protocol)
SIP (Session Initiation Protocol)SIP (Session Initiation Protocol)
SIP (Session Initiation Protocol)KHNOG
 
Denoising auto encoders(d a)
Denoising auto encoders(d a)Denoising auto encoders(d a)
Denoising auto encoders(d a)Tae Young Lee
 
Python Network Programming
Python Network ProgrammingPython Network Programming
Python Network ProgrammingTae Young Lee
 
Sns(social network service)
Sns(social network service)Sns(social network service)
Sns(social network service)Tae Young Lee
 
Machine learning in spam
Machine learning in spamMachine learning in spam
Machine learning in spamTae Young Lee
 
DEVNET-1001 Coding 101: How to Call REST APIs from a REST Client and Python
DEVNET-1001 Coding 101: How to Call REST APIs from a REST Client and PythonDEVNET-1001 Coding 101: How to Call REST APIs from a REST Client and Python
DEVNET-1001 Coding 101: How to Call REST APIs from a REST Client and PythonCisco DevNet
 
Learn REST API with Python
Learn REST API with PythonLearn REST API with Python
Learn REST API with PythonLarry Cai
 

Destacado (16)

Rapid Ring Protection Protocol (RRPP)
Rapid Ring Protection Protocol (RRPP)Rapid Ring Protection Protocol (RRPP)
Rapid Ring Protection Protocol (RRPP)
 
Understanding REST APIs in 5 Simple Steps
Understanding REST APIs in 5 Simple StepsUnderstanding REST APIs in 5 Simple Steps
Understanding REST APIs in 5 Simple Steps
 
Python101
Python101Python101
Python101
 
Bidirectional Forwarding Detection (BFD)
Bidirectional Forwarding Detection (BFD) Bidirectional Forwarding Detection (BFD)
Bidirectional Forwarding Detection (BFD)
 
Network Mapper (NMAP)
Network Mapper (NMAP)Network Mapper (NMAP)
Network Mapper (NMAP)
 
Policy Based Routing (PBR)
Policy Based Routing (PBR)Policy Based Routing (PBR)
Policy Based Routing (PBR)
 
Routing Implementation - Cisco vs. Mikrotik
Routing Implementation - Cisco vs. MikrotikRouting Implementation - Cisco vs. Mikrotik
Routing Implementation - Cisco vs. Mikrotik
 
IT Service Level Agreement
IT Service Level AgreementIT Service Level Agreement
IT Service Level Agreement
 
SIP (Session Initiation Protocol)
SIP (Session Initiation Protocol)SIP (Session Initiation Protocol)
SIP (Session Initiation Protocol)
 
Denoising auto encoders(d a)
Denoising auto encoders(d a)Denoising auto encoders(d a)
Denoising auto encoders(d a)
 
Python Network Programming
Python Network ProgrammingPython Network Programming
Python Network Programming
 
Sns(social network service)
Sns(social network service)Sns(social network service)
Sns(social network service)
 
Machine learning in spam
Machine learning in spamMachine learning in spam
Machine learning in spam
 
DEVNET-1001 Coding 101: How to Call REST APIs from a REST Client and Python
DEVNET-1001 Coding 101: How to Call REST APIs from a REST Client and PythonDEVNET-1001 Coding 101: How to Call REST APIs from a REST Client and Python
DEVNET-1001 Coding 101: How to Call REST APIs from a REST Client and Python
 
Learn REST API with Python
Learn REST API with PythonLearn REST API with Python
Learn REST API with Python
 
JSON and REST
JSON and RESTJSON and REST
JSON and REST
 

Similar a Introduction to Python

Hack Like It's 2013 (The Workshop)
Hack Like It's 2013 (The Workshop)Hack Like It's 2013 (The Workshop)
Hack Like It's 2013 (The Workshop)Itzik Kotler
 
Python programming workshop session 1
Python programming workshop session 1Python programming workshop session 1
Python programming workshop session 1Abdul Haseeb
 
FUNDAMENTALS OF PYTHON LANGUAGE
 FUNDAMENTALS OF PYTHON LANGUAGE  FUNDAMENTALS OF PYTHON LANGUAGE
FUNDAMENTALS OF PYTHON LANGUAGE Saraswathi Murugan
 
Python introduction towards data science
Python introduction towards data sciencePython introduction towards data science
Python introduction towards data sciencedeepak teja
 
pa-pe-pi-po-pure Python Text Processing
pa-pe-pi-po-pure Python Text Processingpa-pe-pi-po-pure Python Text Processing
pa-pe-pi-po-pure Python Text ProcessingRodrigo Senra
 
Hands on Session on Python
Hands on Session on PythonHands on Session on Python
Hands on Session on PythonSumit Raj
 
An Intro to Python in 30 minutes
An Intro to Python in 30 minutesAn Intro to Python in 30 minutes
An Intro to Python in 30 minutesSumit Raj
 
Python_Haegl.powerpoint presentation. tx
Python_Haegl.powerpoint presentation. txPython_Haegl.powerpoint presentation. tx
Python_Haegl.powerpoint presentation. txvishwanathgoudapatil1
 
01-Python-Basics.ppt
01-Python-Basics.ppt01-Python-Basics.ppt
01-Python-Basics.pptVicVic56
 
Python Basics
Python BasicsPython Basics
Python BasicsPooja B S
 
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...DRVaibhavmeshram1
 
Chapter01_Python.ppt
Chapter01_Python.pptChapter01_Python.ppt
Chapter01_Python.pptPigPug1
 
Becoming a Pythonist
Becoming a PythonistBecoming a Pythonist
Becoming a PythonistRaji Engg
 
جلسه اول پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
جلسه اول پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲جلسه اول پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
جلسه اول پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲Mohammad Reza Kamalifard
 
Python bootcamp - C4Dlab, University of Nairobi
Python bootcamp - C4Dlab, University of NairobiPython bootcamp - C4Dlab, University of Nairobi
Python bootcamp - C4Dlab, University of Nairobikrmboya
 

Similar a Introduction to Python (20)

Hack Like It's 2013 (The Workshop)
Hack Like It's 2013 (The Workshop)Hack Like It's 2013 (The Workshop)
Hack Like It's 2013 (The Workshop)
 
Python programming workshop session 1
Python programming workshop session 1Python programming workshop session 1
Python programming workshop session 1
 
Pythonppt28 11-18
Pythonppt28 11-18Pythonppt28 11-18
Pythonppt28 11-18
 
FUNDAMENTALS OF PYTHON LANGUAGE
 FUNDAMENTALS OF PYTHON LANGUAGE  FUNDAMENTALS OF PYTHON LANGUAGE
FUNDAMENTALS OF PYTHON LANGUAGE
 
Python introduction towards data science
Python introduction towards data sciencePython introduction towards data science
Python introduction towards data science
 
pa-pe-pi-po-pure Python Text Processing
pa-pe-pi-po-pure Python Text Processingpa-pe-pi-po-pure Python Text Processing
pa-pe-pi-po-pure Python Text Processing
 
Hands on Session on Python
Hands on Session on PythonHands on Session on Python
Hands on Session on Python
 
An Intro to Python in 30 minutes
An Intro to Python in 30 minutesAn Intro to Python in 30 minutes
An Intro to Python in 30 minutes
 
Python_Haegl.powerpoint presentation. tx
Python_Haegl.powerpoint presentation. txPython_Haegl.powerpoint presentation. tx
Python_Haegl.powerpoint presentation. tx
 
01-Python-Basics.ppt
01-Python-Basics.ppt01-Python-Basics.ppt
01-Python-Basics.ppt
 
Python basics
Python basicsPython basics
Python basics
 
python-2021.pdf
python-2021.pdfpython-2021.pdf
python-2021.pdf
 
Python Basics
Python BasicsPython Basics
Python Basics
 
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
 
Chapter01_Python.ppt
Chapter01_Python.pptChapter01_Python.ppt
Chapter01_Python.ppt
 
What is Python?
What is Python?What is Python?
What is Python?
 
Becoming a Pythonist
Becoming a PythonistBecoming a Pythonist
Becoming a Pythonist
 
جلسه اول پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
جلسه اول پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲جلسه اول پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
جلسه اول پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
 
Python bootcamp - C4Dlab, University of Nairobi
Python bootcamp - C4Dlab, University of NairobiPython bootcamp - C4Dlab, University of Nairobi
Python bootcamp - C4Dlab, University of Nairobi
 
A Python Tutorial
A Python TutorialA Python Tutorial
A Python Tutorial
 

Más de KHNOG

Network Attack Counter
Network Attack CounterNetwork Attack Counter
Network Attack CounterKHNOG
 
Wireless Network Pentestration
Wireless Network PentestrationWireless Network Pentestration
Wireless Network PentestrationKHNOG
 
Core Concept of TCP/IP
Core Concept of TCP/IPCore Concept of TCP/IP
Core Concept of TCP/IPKHNOG
 
Bonding Interface in MikroTik
Bonding Interface in MikroTikBonding Interface in MikroTik
Bonding Interface in MikroTikKHNOG
 
Network Exploitation
Network ExploitationNetwork Exploitation
Network ExploitationKHNOG
 
Network Security-Honeypot
Network Security-HoneypotNetwork Security-Honeypot
Network Security-HoneypotKHNOG
 
Bandwidth Management on Linux
Bandwidth Management on LinuxBandwidth Management on Linux
Bandwidth Management on LinuxKHNOG
 
Why / How to become the Linux certified
Why / How to become the Linux certifiedWhy / How to become the Linux certified
Why / How to become the Linux certifiedKHNOG
 
Terminal Access Controller
Terminal Access ControllerTerminal Access Controller
Terminal Access ControllerKHNOG
 
Cambodia International Backbone Network
Cambodia International Backbone NetworkCambodia International Backbone Network
Cambodia International Backbone NetworkKHNOG
 
Introduction to BRAS
Introduction to BRASIntroduction to BRAS
Introduction to BRASKHNOG
 
ElasticISP
ElasticISPElasticISP
ElasticISPKHNOG
 
Hotspot on Mikrotik Router
Hotspot on Mikrotik RouterHotspot on Mikrotik Router
Hotspot on Mikrotik RouterKHNOG
 
Virtual Extensible LAN (VXLAN)
Virtual Extensible LAN (VXLAN)Virtual Extensible LAN (VXLAN)
Virtual Extensible LAN (VXLAN)KHNOG
 
Transmission Technologies
Transmission TechnologiesTransmission Technologies
Transmission TechnologiesKHNOG
 
Interior Routing Protocols
Interior Routing ProtocolsInterior Routing Protocols
Interior Routing ProtocolsKHNOG
 
Mikrotik Hotspot User Manager
Mikrotik Hotspot User ManagerMikrotik Hotspot User Manager
Mikrotik Hotspot User ManagerKHNOG
 
Testing Fiber-Optic Systems
Testing Fiber-Optic Systems Testing Fiber-Optic Systems
Testing Fiber-Optic Systems KHNOG
 
RPM Junos-service
RPM Junos-serviceRPM Junos-service
RPM Junos-serviceKHNOG
 
Incoming Outgoing Spam Filter
Incoming Outgoing Spam FilterIncoming Outgoing Spam Filter
Incoming Outgoing Spam FilterKHNOG
 

Más de KHNOG (20)

Network Attack Counter
Network Attack CounterNetwork Attack Counter
Network Attack Counter
 
Wireless Network Pentestration
Wireless Network PentestrationWireless Network Pentestration
Wireless Network Pentestration
 
Core Concept of TCP/IP
Core Concept of TCP/IPCore Concept of TCP/IP
Core Concept of TCP/IP
 
Bonding Interface in MikroTik
Bonding Interface in MikroTikBonding Interface in MikroTik
Bonding Interface in MikroTik
 
Network Exploitation
Network ExploitationNetwork Exploitation
Network Exploitation
 
Network Security-Honeypot
Network Security-HoneypotNetwork Security-Honeypot
Network Security-Honeypot
 
Bandwidth Management on Linux
Bandwidth Management on LinuxBandwidth Management on Linux
Bandwidth Management on Linux
 
Why / How to become the Linux certified
Why / How to become the Linux certifiedWhy / How to become the Linux certified
Why / How to become the Linux certified
 
Terminal Access Controller
Terminal Access ControllerTerminal Access Controller
Terminal Access Controller
 
Cambodia International Backbone Network
Cambodia International Backbone NetworkCambodia International Backbone Network
Cambodia International Backbone Network
 
Introduction to BRAS
Introduction to BRASIntroduction to BRAS
Introduction to BRAS
 
ElasticISP
ElasticISPElasticISP
ElasticISP
 
Hotspot on Mikrotik Router
Hotspot on Mikrotik RouterHotspot on Mikrotik Router
Hotspot on Mikrotik Router
 
Virtual Extensible LAN (VXLAN)
Virtual Extensible LAN (VXLAN)Virtual Extensible LAN (VXLAN)
Virtual Extensible LAN (VXLAN)
 
Transmission Technologies
Transmission TechnologiesTransmission Technologies
Transmission Technologies
 
Interior Routing Protocols
Interior Routing ProtocolsInterior Routing Protocols
Interior Routing Protocols
 
Mikrotik Hotspot User Manager
Mikrotik Hotspot User ManagerMikrotik Hotspot User Manager
Mikrotik Hotspot User Manager
 
Testing Fiber-Optic Systems
Testing Fiber-Optic Systems Testing Fiber-Optic Systems
Testing Fiber-Optic Systems
 
RPM Junos-service
RPM Junos-serviceRPM Junos-service
RPM Junos-service
 
Incoming Outgoing Spam Filter
Incoming Outgoing Spam FilterIncoming Outgoing Spam Filter
Incoming Outgoing Spam Filter
 

Último

Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 

Último (20)

Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 

Introduction to Python

  • 1. Introduction to Python for Network Engineer (Basic)
  • 2. Before We Start Do you know these following languages? ´  C/C++ ´  Java ´  Shell ´  Batch ´  TCL ´  Python
  • 3. Python Overview ´  A script programming language ´  A high-level programming language  ´  object-oriented ´  No compilation ´  No datatype declaration
  • 4. What can Python do? Many many things which Python could do but the only one thing we will talk about is “ Network Automation”
  • 5. Running Python: Interactively Python is pre-installed on Linux platform [porhai@python ~]$ python Python 2.6.6 (r266:84292, Jul 23 2015, 15:22:56) [GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> >>> print "Hello world" Hello world >>>
  • 6. Running Python: .py file [porhai@python ~]$ vi khnog.py print "hello world" ~ ~ [porhai@python ~]$ python khnog.py hello world [porhai@python ~]$
  • 7. Python VS Shell [porhai@python ~]$ echo Hello World Hello World [porhai@python ~]$ >>> print "Hello world" Hello world >>> Shell Python
  • 8. Python VS Shell [porhai@python ~]$ vi khnog.sh echo Hello World ~ [porhai@python ~]$ sh khnog.sh Hello World [porhai@python ~]$ Shell Python [porhai@python ~]$ vi khnog.py print "hello world" ~ [porhai@python ~]$ python khnog.py hello world [porhai@python ~]$
  • 9. Python Input/Output >>> x = raw_input("x = ") x = 123 >>> >>> print x 123
  • 10. Python Datatypes ´  Integer (int) ´  Float (float) ´  String (str) ´  List (list) ´  Dictionary (dict) >>> x=1 >>> type(x) <type 'int'> >>> x="hello" >>> type(x) <type 'str'> >>> >>> x=[1,2,3] >>> type(x) <type 'list'> >>> x={'name':'porhai', 'age':22} >>> type(x) <type 'dict'> >>> x=1.1 >>> type(x) <type 'float'>
  • 11. Python Modules ´  Telnetlib ´  Paramiko ´  Smtplib ´  PySNMP
  • 12. Python Program Example ´  Login to Switch ´  Enter Username and Password ´  Get configuration of interface ´  Output result
  • 13. Python Code [porhai@python ~]$ vi khnog.py import telnetlib def open_telnet_conn(ip): #Change exception message try: #Define telnet parameters username = 'porhai' password = 'porhai' TELNET_PORT = 23 #Logging into device connection = telnetlib.Telnet(ip, TELNET_PORT, TELNET_TIMEOUT)
  • 14. Python Code connection.write(username + "n") connection.write(password + "n") time.sleep(1) connection.write("show run int g0/1 n") time.sleep(1) Output = connection.read_very_eager() print Output #Closing the connection connection.close() except IOError: print "Input parameter error! Please check username, password and file name." open_telnet_conn("10.1.1.1")
  • 15. Python Program Executed [porhai@python ~]$ python khnog.py User Access Verification Username: porhai Password: S1#show run int g0/1 Building configuration... Current configuration : 66 bytes ! interface GigabitEthernet0/1 no switchport no ip address end
  • 16. Reference ´  Python Language Comparison https://www.python.org/doc/essays/comparisons/ Shell ´  Python Lesson http://learnpythonthehardway.org/ ´  Python for Network Engineers https://pynet.twb-tech.com/