Book Image

Mastering Python for Networking and Security

By : José Ortega
Book Image

Mastering Python for Networking and Security

By: José Ortega

Overview of this book

It’s becoming more and more apparent that security is a critical aspect of IT infrastructure. A data breach is a major security incident, usually carried out by just hacking a simple network line. Increasing your network’s security helps step up your defenses against cyber attacks. Meanwhile, Python is being used for increasingly advanced tasks, with the latest update introducing many new packages. This book focuses on leveraging these updated packages to build a secure network with the help of Python scripting. This book covers topics from building a network to the different procedures you need to follow to secure it. You’ll first be introduced to different packages and libraries, before moving on to different ways to build a network with the help of Python scripting. Later, you will learn how to check a network’s vulnerability using Python security scripting, and understand how to check vulnerabilities in your network. As you progress through the chapters, you will also learn how to achieve endpoint protection by leveraging Python packages along with writing forensic scripts. By the end of this book, you will be able to get the most out of the Python language to build secure and robust networks that are resilient to attacks.
Table of Contents (16 chapters)

The main development environments for script-development

In this section, we will review Pycharm and WingIDE as development environments for python scripting.

Setting up a development environment

Pycharm

PyCharm is an IDE developed by the company Jetbrains, and is based on IntelliJ IDEA, the IDE of the same company, but focused on Java and is the base for Android Studio.

PyCharm is multi-platform and we can find binaries for Windows, Linux, and macOS X. There are two versions of PyCharm: community and professional, with differences in features related to integration with web frameworks and database support.

In this url we can see a comparison between community and professional edition: http://www.jetbrains.com/pycharm

The main advantages of this development environment are:

  • Autocomplete, syntax highlighter, analysis tool and refactoring.
  • Integration with web frameworks such as Django, Flask, Pyramid, Web2Py, jQuery, and AngularJS.
  • Advanced debugger.
  • Compatible with SQLAlchemy (ORM), Google App Engine, Cython.
  • Connection with version-control systems: Git, CVS, Mercurial.

WingIDE

WingIDE is a multi-platform environment available for Windows, Mac, and Linux and provides all the functionalities at the level of debugging and variables-exploration.

WingIDE has a rich feature set that will easily support the development of sophisticated Python Applications. With WingIDE, you are able to inspect variables, stack arguments, and memory locations without the process changing any of their values before you can record them. Breakpoints are the most common feature that you will use when debugging a process. Wing Personal is the free version of this Python IDE, which can be found at https://wingware.com/downloads/wingide-personal

WingIDE uses the Python configuration installed in your system:

Debugging with WingIDE

In this example, we are debugging a Python script that accepts two input parameters:

An interesting topic is the possibility of adding a breakpoint in our program with the option Add Breakpoint option, in this way, we can debug and see the contents of the variables just at the point where we have established the breakpoint:

We can set a breakpoint in the call to the view_parameters method.

To execute a script in debug mode with parameters, you have to edit the properties of the script and add the parameters that our script needs within the debug tag:

If we execute in debug mode with a breakpoint inside the function, we can see the content of the parameters in local string variables:

In the following screenshot we can visualize the values of the params variable that contains the values we are debugging: