SlideShare a Scribd company logo
Python for ethical hackers
Mohammad reza Kamalifard
kamalifard@datasec.ir
Python language essentials
Module 1:
Introduction to Python and Setting up an Environment for Programing
Part 7 :
Exception Handling
Exceptions
Simply put exceptions are error condtions which disrupt the normal
flow of the program
Python allows for a simple and elegant way to handle exceptions
>>> 0/0
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ZeroDivisionError: integer division or modulo by zero
Python Standard Exceptions
http://www.tutorialspoint.com/python/standard_exceptions.htm
Exception Handling
>>> try:
...
print 0/0
... except:
...
print 'Exception Happened'
...
Exception Happened
>>>
>>> try:
...
print 100/10
... except:
...
print 'Exception'
...
10
>>>
else and finally
>>> try:
...
print 10/2
... except:
...
print 'Exception'
... else:
...
print 'No Exception'
... finally:
...
print 'Cleanup code always here'
...
5
No Exception
Cleanup code always here
>>>
else and finally
>>> try:
...
print 10/0
... except:
...
print 'Exception'
... else:
...
print 'No Exception'
... finally:
...
print 'Cleanup code always here'
...
Exception
Cleanup code always here
>>>
>>> try:
...
10/0
... except ZeroDivisionError:
...
print 'Divided by Zero'
...
Divided by Zero
>>>
>>> try:
...
10/0
... except Exception as err:
...
print err
...
integer division or modulo by zero
>>> try:
...
print name
... except Exception as err:
...
print err
...
name 'name' is not defined
>>>
References
SPSE securitytube training by Vivek Ramachandran
SANS Python for Pentesters (SEC573)
Violent python
Security Power Tools
python-course.eu
----------------------------http://www.python-course.eu/exception_handling.php
http://www.tutorialspoint.com/python/python_exceptions.htm
http://www.wilfred.me.uk/blog/2013/11/03/no-naked-excepts/
This work is licensed under the Creative Commons Attribution-NoDerivs 3.0 Unported License.
To view a copy of this license, visit
http://creativecommons.org/licenses/by-nd/3.0/
Copyright 2013 Mohammad Reza Kamalifard
All rights reserved.
Go to Kamalifard.ir/pysec101 to Download Slides and Course martials .

More Related Content

PDF
اسلاید اول جلسه هفتم کلاس پایتون برای هکرهای قانونی
PDF
GCE Windows Serial Console Usage Guide
PDF
اسلاید دوم جلسه هفتم کلاس پایتون برای هکرهای قانونی
PDF
جلسه سوم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
PPTX
Raccoon rabies
PDF
Tehlug 26 Nov 2013 Hackers,Cyberwarfare and Online privacy
PDF
جلسه پنجم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۱
اسلاید اول جلسه هفتم کلاس پایتون برای هکرهای قانونی
GCE Windows Serial Console Usage Guide
اسلاید دوم جلسه هفتم کلاس پایتون برای هکرهای قانونی
جلسه سوم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
Raccoon rabies
Tehlug 26 Nov 2013 Hackers,Cyberwarfare and Online privacy
جلسه پنجم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۱

Similar to جلسه ششم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۱ (20)

PPTX
Exception handling with python class 12.pptx
PPTX
Exception handling.pptxnn h
PDF
lecs101.pdfgggggggggggggggggggddddddddddddb
PDF
Python Programming - X. Exception Handling and Assertions
PPTX
Exception Handling in python programming.pptx
PPTX
Python Programming Essentials - M21 - Exception Handling
PPTX
Python_Exception_Handling_Presentation.pptx
PPTX
Error and exception in python
PDF
Python programming : Exceptions
PDF
Exception handling in python
PPTX
Exception handling in python
PPTX
Python Exceptions Powerpoint Presentation
PPT
33aa27cae9c84fd12762a4ecdc288df822623524-1705207147822.ppt
PDF
Unit 4-Exception Handling in Python.pdf
PPTX
Exception Handling in Python topic .pptx
PPTX
Python Exception Handling
PPTX
Errorhandlingbyvipulkendroyavidyalayacrpfmudkhed.pptx
PPTX
Python Lecture 7
PPTX
Download Wondershare Filmora Crack Latest 2025
PPTX
Adobe Photoshop 2025 Cracked Latest Version
Exception handling with python class 12.pptx
Exception handling.pptxnn h
lecs101.pdfgggggggggggggggggggddddddddddddb
Python Programming - X. Exception Handling and Assertions
Exception Handling in python programming.pptx
Python Programming Essentials - M21 - Exception Handling
Python_Exception_Handling_Presentation.pptx
Error and exception in python
Python programming : Exceptions
Exception handling in python
Exception handling in python
Python Exceptions Powerpoint Presentation
33aa27cae9c84fd12762a4ecdc288df822623524-1705207147822.ppt
Unit 4-Exception Handling in Python.pdf
Exception Handling in Python topic .pptx
Python Exception Handling
Errorhandlingbyvipulkendroyavidyalayacrpfmudkhed.pptx
Python Lecture 7
Download Wondershare Filmora Crack Latest 2025
Adobe Photoshop 2025 Cracked Latest Version
Ad

More from Mohammad Reza Kamalifard (20)

PDF
PDF
Introduction to Flask Micro Framework
PDF
Pycon - Python for ethical hackers
PDF
جلسه دوم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
PDF
جلسه چهارم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
PDF
جلسه پنجم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۲
PDF
جلسه ششم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۲
PDF
جلسه هفتم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
PDF
جلسه اول پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
PDF
اسلاید اول جلسه اول دوره پاییز کلاس پایتون برای هکرهای قانونی
PDF
اسلاید دوم جلسه یازدهم کلاس پایتون برای هکر های قانونی
PDF
اسلاید اول جلسه یازدهم کلاس پایتون برای هکرهای قانونی
PDF
اسلاید ارائه دوم جلسه ۱۰ کلاس پایتون برای هکر های قانونی
PDF
اسلاید ارائه اول جلسه ۱۰ کلاس پایتون برای هکر های قانونی
PDF
اسلاید ارائه سوم جلسه ۱۰ کلاس پایتون برای هکر های قانونی
PDF
اسلاید جلسه ۹ کلاس پایتون برای هکر های قانونی
PDF
اسلاید اول جلسه هشتم کلاس پایتون برای هکرهای قانونی
PDF
اسلاید سوم جلسه هفتم کلاس پایتون برای هکرهای قانونی
PDF
اسلاید اول جلسه پنجم کلاس پایتون برای هکرهای قانونی
PDF
اسلاید دوم جلسه پنجم کلاس پایتون برای هکرهای قانونی
Introduction to Flask Micro Framework
Pycon - Python for ethical hackers
جلسه دوم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
جلسه چهارم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
جلسه پنجم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۲
جلسه ششم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۲
جلسه هفتم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
جلسه اول پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
اسلاید اول جلسه اول دوره پاییز کلاس پایتون برای هکرهای قانونی
اسلاید دوم جلسه یازدهم کلاس پایتون برای هکر های قانونی
اسلاید اول جلسه یازدهم کلاس پایتون برای هکرهای قانونی
اسلاید ارائه دوم جلسه ۱۰ کلاس پایتون برای هکر های قانونی
اسلاید ارائه اول جلسه ۱۰ کلاس پایتون برای هکر های قانونی
اسلاید ارائه سوم جلسه ۱۰ کلاس پایتون برای هکر های قانونی
اسلاید جلسه ۹ کلاس پایتون برای هکر های قانونی
اسلاید اول جلسه هشتم کلاس پایتون برای هکرهای قانونی
اسلاید سوم جلسه هفتم کلاس پایتون برای هکرهای قانونی
اسلاید اول جلسه پنجم کلاس پایتون برای هکرهای قانونی
اسلاید دوم جلسه پنجم کلاس پایتون برای هکرهای قانونی
Ad

Recently uploaded (20)

PDF
01-Introduction-to-Information-Management.pdf
PDF
RMMM.pdf make it easy to upload and study
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
master seminar digital applications in india
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
Cell Types and Its function , kingdom of life
PPTX
Cell Structure & Organelles in detailed.
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PDF
Basic Mud Logging Guide for educational purpose
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
01-Introduction-to-Information-Management.pdf
RMMM.pdf make it easy to upload and study
102 student loan defaulters named and shamed – Is someone you know on the list?
FourierSeries-QuestionsWithAnswers(Part-A).pdf
O7-L3 Supply Chain Operations - ICLT Program
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Supply Chain Operations Speaking Notes -ICLT Program
master seminar digital applications in india
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PPH.pptx obstetrics and gynecology in nursing
Module 4: Burden of Disease Tutorial Slides S2 2025
Cell Types and Its function , kingdom of life
Cell Structure & Organelles in detailed.
2.FourierTransform-ShortQuestionswithAnswers.pdf
Abdominal Access Techniques with Prof. Dr. R K Mishra
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
Basic Mud Logging Guide for educational purpose
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
school management -TNTEU- B.Ed., Semester II Unit 1.pptx

جلسه ششم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۱

  • 1. Python for ethical hackers Mohammad reza Kamalifard kamalifard@datasec.ir
  • 2. Python language essentials Module 1: Introduction to Python and Setting up an Environment for Programing Part 7 : Exception Handling
  • 3. Exceptions Simply put exceptions are error condtions which disrupt the normal flow of the program Python allows for a simple and elegant way to handle exceptions >>> 0/0 Traceback (most recent call last): File "<stdin>", line 1, in <module> ZeroDivisionError: integer division or modulo by zero Python Standard Exceptions http://www.tutorialspoint.com/python/standard_exceptions.htm
  • 4. Exception Handling >>> try: ... print 0/0 ... except: ... print 'Exception Happened' ... Exception Happened >>> >>> try: ... print 100/10 ... except: ... print 'Exception' ... 10 >>>
  • 5. else and finally >>> try: ... print 10/2 ... except: ... print 'Exception' ... else: ... print 'No Exception' ... finally: ... print 'Cleanup code always here' ... 5 No Exception Cleanup code always here >>>
  • 6. else and finally >>> try: ... print 10/0 ... except: ... print 'Exception' ... else: ... print 'No Exception' ... finally: ... print 'Cleanup code always here' ... Exception Cleanup code always here >>>
  • 7. >>> try: ... 10/0 ... except ZeroDivisionError: ... print 'Divided by Zero' ... Divided by Zero >>>
  • 8. >>> try: ... 10/0 ... except Exception as err: ... print err ... integer division or modulo by zero >>> try: ... print name ... except Exception as err: ... print err ... name 'name' is not defined >>>
  • 9. References SPSE securitytube training by Vivek Ramachandran SANS Python for Pentesters (SEC573) Violent python Security Power Tools python-course.eu ----------------------------http://www.python-course.eu/exception_handling.php http://www.tutorialspoint.com/python/python_exceptions.htm http://www.wilfred.me.uk/blog/2013/11/03/no-naked-excepts/
  • 10. This work is licensed under the Creative Commons Attribution-NoDerivs 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nd/3.0/ Copyright 2013 Mohammad Reza Kamalifard All rights reserved. Go to Kamalifard.ir/pysec101 to Download Slides and Course martials .