Book Image

Learning Python Networking - Second Edition

By : José Manuel Ortega, Dr. M. O. Faruque Sarker, Sam Washington
Book Image

Learning Python Networking - Second Edition

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

Overview of this book

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.
Table of Contents (19 chapters)
Free Chapter
1
Section 1: Introduction to Network and HTTP Programming
4
Section 2: Interacting with APIs, Web Scraping, and Server Scripting
9
Section 3: IP Address Manipulation and Network Automation
13
Section 4: Sockets and Server Programming

What this book covers

Chapter 1, Network Programming with Python, provides a review of basic network elements and principles. It discusses how Python supports network programming and gives an overview of key libraries. It also provides an introduction to Wireshark as a protocol exploration and network programming diagnostic tool. Furthermore, we will review how we can interact with Wireshark from Python with the pyshark module.

Chapter 2, Programming for the Web with HTTP, covers the HTTP protocol and the main Python modules, such as the urllib standard library and the requests package for connecting with the REST API. It also covers HTTP authentication mechanisms and how we can manage them by means of the requests module.

Chapter 3, Application Programming Interface in Action, covers how to use Python to extract data from the major data formats found on the web: HTML, XML, and JSON. An example of interacting with REST APIs, such as Twitter and Amazon S3, will be used to guide the reader through the essentials of working with XML and JSON.

Chapter 4, Web Scraping with BeautifulSoup and Scrapy, covers how to extract the content of a web page by automating the information extraction process using scraping techniques to recover data from the web automatically. This chapter also covers some of the most powerful tools we can find in Python 3.7, with a focus on BeautifulSoup and Scrapy.

Chapter 5, Engaging with Email, explores the Python modules that facilitate communication with email servers using SMTP, POP3, and IMAP protocols. Practical code examples in Python 3.7 will illustrate the majority of concepts.

Chapter 6, Interacting with Remote Systems, explains the different modules that allow us to interact with FTP, SSH, SNMP, and LDAP servers. You will learn about several network protocols and Python libraries that are used for interacting with remote systems through the Python modules, including ftplib, paramiko, pysnmp, and python-ldap.

Chapter 7, Working with IP and DNS, explores how to work with IPs, DNS networking, and geolocation in Python. You will learn about acquiring information for DNS servers using the DNSPython module and extracting information relating to geolocation IP addresses.

Chapter 8, Implementing IPv6 and Address Manipulation, explains how to work with IPv6 and address manipulation with Python. You will learn by means of practical tasks, such as determining the IP address of your own computer and looking up other computers in the local network.

Chapter 9, Performing Network Automation with Python and Ansible, covers the principles of Ansible and how we can interact with Python. We will review how to write a Python script with a view to executing a networking automation task with Ansible and how to write an Ansible module with Python.

Chapter 10, Programming with Sockets, introduces the basics of sockets and the principles of UDP and TCP through examples involving the socket module with the IPv4 and IPv6 protocols. We will also cover non-blocking and asynchronous programming and HTTPS and TLS for secure data transport.

Chapter 11, Designing Servers and Asynchronous Programming, covers the principles of socket-based server design and how to build small servers based on multiprocessing approaches. We review asyncio and aiohttp for asynchronous operations and other solutions, such as Tornado, Twisted, and Celery, for building asynchronous network applications.

Chapter 12, Designing Applications on the Web, introduces the Django and Flask micro frameworks, which are designed to facilitate the development of web applications under the Model View Controller (MVC) pattern. Finally, we review how to work with HTTP requests in Flask and interact with databases through SQLAlchemy.