Learning Python Networking
eBook - ePub

Learning Python Networking

A complete guide to build and deploy strong networking capabilities using Python 3.7 and Ansible , 2nd Edition

José Manuel Ortega, Dr. M. O. Faruque Sarker, Sam Washington

Share book
  1. 490 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Learning Python Networking

A complete guide to build and deploy strong networking capabilities using Python 3.7 and Ansible , 2nd Edition

José Manuel Ortega, Dr. M. O. Faruque Sarker, Sam Washington

Book details
Book preview
Table of contents
Citations

About This Book

Achieve improved network programmability and automation by leveraging powerful network programming concepts, algorithms, and tools

Key Features

  • Deal with remote network servers using SSH, FTP, SNMP and LDAP protocols.
  • Design multi threaded and event-driven architectures for asynchronous servers programming.
  • Leverage your Python programming skills to build powerful network applications

Book Description

Network programming has always been a demanding task. With full-featured and well-documented libraries all the way up the stack, Python makes network programming the enjoyable experience it should be.

Starting with a walk through of today's major networking protocols, through this book, you'll learn how to employ Python for network programming, how to request and retrieve web resources, and how to extract data in major formats over the web. You will utilize Python for emailing using different protocols, and you'll interact with remote systems and IP and DNS networking. You will cover the connection of networking devices and configuration using Python 3.7, along with cloud-based network management tasks using Python.

As the book progresses, socket programming will be covered, followed by how to design servers, and the pros and cons of multithreaded and event-driven architectures. You'll develop practical clientside applications, including web API clients, email clients, SSH, and FTP. These applications will also be implemented through existing web application frameworks.

What you will learn

  • Execute Python modules on networking tools
  • Automate tasks regarding the analysis and extraction of information from a network
  • Get to grips with asynchronous programming modules available in Python
  • Get to grips with IP address manipulation modules using Python programming
  • Understand the main frameworks available in Python that are focused on web application
  • Manipulate IP addresses and perform CIDR calculations

Who this book is for

If you're a Python developer or a system administrator with Python experience and you're looking to take your first steps in network programming, then this book is for you. If you're a network engineer or a network professional aiming to be more productive and efficient in networking programmability and automation then this book would serve as a useful resource. Basic knowledge of Python is assumed.

Frequently asked questions

How do I cancel my subscription?
Simply head over to the account section in settings and click on “Cancel Subscription” - it’s as simple as that. After you cancel, your membership will stay active for the remainder of the time you’ve paid for. Learn more here.
Can/how do I download books?
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
What is the difference between the pricing plans?
Both plans give you full access to the library and all of Perlego’s features. The only differences are the price and subscription period: With the annual plan you’ll save around 30% compared to 12 months on the monthly plan.
What is Perlego?
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Do you support text-to-speech?
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Is Learning Python Networking an online PDF/ePUB?
Yes, you can access Learning Python Networking by José Manuel Ortega, Dr. M. O. Faruque Sarker, Sam Washington in PDF and/or ePUB format, as well as other popular books in Computer Science & Programming in Python. We have over one million books available in our catalogue for you to explore.

Information

Year
2019
ISBN
9781789952445
Edition
2

Section 1: Introduction to Network and HTTP Programming

In this section, you will learn about the basics of Python network programming, networking protocols, and the main modules for interacting with HTTP servers.
This section contains the following chapters:
  • Chapter 1, Network Programming with Python
  • Chapter 2, Programming for the Web with HTTP

Network Programming with Python

This book will focus on writing programs for networks that use the Internet Protocol (IP) suite. Why have we chosen to do this? Well, out of the sets of protocols that are supported by the Python standard library, the Transmission Control Protocol (TCP)/IP protocol is by far the most widely employable. It contains the principal protocols that are used by the internet. By learning to program for TCP/IP, you'll be learning how to potentially communicate with just about every device that is connected to this great tangle of network cables and electromagnetic waves.
The following topics will be covered in this chapter:
  • An introduction to TCP/IP networking
  • Protocol concepts and the problems that protocols solve
  • Addressing
  • Creating RESTful web applications and working with flask and HTTP requests
  • Interacting flask with the SQLAlchemy database
In this chapter, we will be looking at some concepts and methods related to networks and network programming in Python, which we'll be using throughout this book.
This chapter has two sections. The first section, An introduction to TCP/IP networking, offers an introduction to essential networking concepts, with a strong focus on the TCP/IP stack. We'll be looking at what comprises a network, how the IP allows data transfer across and between networks, and how TCP/IP provides us with services that help us to develop network applications. This section is intended to provide a grounding in these essential areas and to act as a point of reference for them. If you're already comfortable with concepts such as IP addresses, routing, TCP and User Datagram Protocol (UDP), and protocol stack layers, then you may wish to skip to the second section, Python network programming through libraries.
In the second part, we'll look at the way in which network programming is approached with Python. This chapter provides a review of basic network elements and principles, as well as a discussion of how Python supports network programming with an overview of key libraries. Finally, we will introduce you to Wireshark, a protocol exploration and network programming diagnostic tool. We will also look at how we can interact with Wireshark from Python with the pyshark module.

Technical requirements

Before you start reading this book, you should already know the basics of Python programming, such as the basic syntax, variable types, data type tuple, list dictionary, functions, strings, and methods. At the moment of writing this book, versions 3.7.2 and 2.7.15 are available at python.org/downloads. In this book, we will work with version 3.7 for code examples and installing packages.
The examples and source code for this chapter are available in this book's GitHub repository in the Chapter01 folder: https://github.com/PacktPublishing/Learning-Python-Networking-Second-Edition.

An introduction to TCP/IP networking

This first section offers an introduction to essential networking concepts, with a strong focus on the TCP/IP stack.
The following discussion is based on Internet Protocol version 4 (IPv4). Since the internet has run out of IPv4 addresses, a new version, IPv6, has been developed, which is intended to resolve this situation. However, although IPv6 is being used in a few areas, its deployment is progressing slowly and the majority of the internet will likely be using IPv4 for a while longer. We'll focus on IPv4 in this section, and then we will discuss the relevant changes in the IPv6 section of this chapter.

Introduction to TCP/IP

TCP/IP is a set of protocols that were designed to work together to provide an end-to-end transmission of messages across interconnected networks. TCP provides transparent data transfers between end systems using the services of the lower network layer to move the packets between the two communicating systems. TCP is a protocol that works at the transport layer, while IP works at the network layer.
TCP is responsible for creating connections through a data flow. This process guarantees that the data is delivered to the destination without errors and in the same order in which they came out. It is also used to distinguish different applications in the same device.
IP is responsible for sending and receiving data in blocks. The shipment always does this to find the best route, but without guaranteeing that it reaches the destination.
Both protocols are used to solve the transmission of data that is generated in a network, either internally or externally. The union of these protocols is done to ensure that the information always arrives on the best route and in the correct way to the destination.

The protocol stack, layer by layer

A protocol stack is organized in such a way that the highest level of communication resides in the top layer. Each layer in the stack is built on the services of the immediate lower layer.
The TCP/IP protocol stack has four layers, as follows:
  • Application layer: This layer manages the high-level protocols, including representation, coding, and dialogue control issues. It handles everything related to applications, and the data is packed appropriately for the next layer. It is a user process that cooperates with other processes on the same host or a different one. Examples of protocols at this layer are TELNET, File Transfer Protocol (FTP), and Simple Mail Transfer Protocol (SMTP).
  • Transport layer: This layer handles quality of service, reliability, flow control, and error correction. One of its protocols is the TCP, which provides reliable network communications that are oriented to the connection, unlike UDP, which is not connection oriented. It also provides data transfer. Example protocols include TCP (connection oriented) and UDP (non-connection oriented).
  • Network layer: The purpose of the internet layer is to send packets from the source of any network and make them reach their destination, regardless of the route they take to get there.
  • Network access layer: This is also called a host-to-host network layer. It includes the LAN and WAN protocols, and the details in the physical and data link layers of the OSI model. Also known as the link layer or data link layer, the network interface layer is the interface to the current network hardware.
The following diagram represents the TCP/IP protocol stack:
The IP is the most important protocol of the network layer. It is a non-connection oriented protocol that does not assume reliability of the lo...

Table of contents