Preface
Python Network Programming reviews the core elements of Python and the TCP/IP protocol suite. It highlights major aspects of Python network programming such as writing simple networking clients, creating and deploying SDN and NFV systems, and extending your network with Mininet. You’ll also learn how to automate legacy and the latest network devices. As you progress through the chapters, you’ll use Python for DevOps and open source tools to test, secure, and analyze your network. This Learning Path will guide you in configuring the Linux Foundation networking ecosystem and deploying automated networks in the cloud. You will gain experience in retrieving network information with flow-based monitoring, a polling mechanism, and data visualization. Toward the end, you'll develop client-side applications, such as web API clients, email clients, SSH, and FTP, using socket programming and multithreaded or event-driven architectures.
By the end of this Learning Path, you will have learned how to analyze a network's security vulnerabilities using advanced network packet capture and analysis techniques.
This Learning Path includes content from the following Packt products:
- Practical Network Automation by Abhishek Ratan
- Mastering Python Networking by Eric Chou
- Python Network Programming Cookbook, Second Edition by Pradeeban Kathiravelu, Dr. M. O. Faruque Sarker
Who this book is for
If you are a Python developer or a system administrator who wants to start network programming, this Learning Path gets you a step closer to your goal. IT professionals and DevOps engineers who are new to managing network devices or those with minimal experience looking to expand their knowledge and skills in Python will also find this Learning Path useful. Although prior knowledge of networking is not required, some experience in Python programming will be helpful for a better understanding of the concepts in the Learning Path.
What this book covers
Chapter 1, Fundamental Concepts, introduces how to get started with automation.
Chapter 2, Python for Network Engineers, introduces to Python as a scripting language, and samples to explain usage of Python in accessing network devices and data parsing from the device outputs.
Chapter 3, Continuous Integration for Network Engineers, gives an overview of integration principles for network engineers to manage rapid growth with high availability and rapid disaster recovery.
Chapter 4, SDN Concepts in Network Automation, talks about moving your enterprise Java applications to virtualized x86 platforms to better utilize resources with easier life cycle and scalability management.
Chapter 5, Low-Level Network Device Interactions, uses practical examples to illustrate how to use Python to execute commands on a network device. It will also discuss the challenges of having a CLI-only interface in automation. The chapter will use the Pexpect and Paramiko libraries for the examples.
Chapter 6, APIs and Intent-Driven Networking, discusses the newer network devices that support Application Programming Interfaces (APIs) and other high-level interaction methods. It also illustrates tools that allow abstraction of low-level tasks while focusing on the intent of the network engineers. A discussion about and examples of Cisco NX-API, Juniper PyEZ, and Arista Pyeapi will be used in the chapter.
Chapter 7, The Python Automation Framework – Ansible Basics, discusses the basics of Ansible, an open source, Python-based automation framework. Ansible moves one step further from APIs and focuses on declarative task intent. In this chapter, we will cover the advantages of using Ansible, its high-level architecture, and see some practical examples of Ansible with Cisco, Juniper, and Arista devices.
Chapter 8, The Python Automation Framework – Beyond Basics, builds on the knowledge in the previous chapter and covers the more advanced Ansible topics. We will cover conditionals, loops, templates, variables, Ansible Vault, and roles. It will also cover the basics of writing custom modules.
Chapter 9, AWS Cloud Networking, shows how we can use AWS to build a virtual network that is functional and resilient. We will cover virtual private cloud technologies such as CloudFormation, VPC routing table, access-list, Elastic IP, NAT Gateway, Direct Connect, and other related topics.
Chapter 10, Working with Git, we will illustrate how we can leverage Git for collaboration and code version control. Practical examples of using Git for network operations will be used in this chapter.
Chapter 11, Sockets, IPv4, and Simple Client/Server Programming, introduces you to Python's core networking library with various small tasks and enables you to create your first clientserver application.
Chapter 12, Multiplexing Socket I/O for Better Performance, discusses various useful techniques for scaling your client/server applications with default and third-party libraries.
Chapter 13, IPv6, Unix Domain Sockets, and Network Interfaces, focuses more on administering your local machine and looking after your local area network.
Chapter 14, Programming with HTTP for the Internet, enables you to create a mini commandline browser with various features such as submitting web forms, handling cookies, managing partial downloads, compressing data, and serving secure content over HTTPS.
Chapter 15, Email Protocols, FTP, and CGI Programming, brings you the joy of automating your FTP and e-mail tasks such as manipulating your Gmail account, and reading or sending emails from a script or creating a guest book for your web application. We learn to write email clients with SMTP and POP3.
Chapter 16, Programming Across Machine Boundaries, gives you a taste of automating your system administration and deployment tasks over SSH. You can run commands, install packages, or set up new websites remotely from your laptop.
Chapter 17, Working with Web Services – XML-RPC, SOAP, and REST, introduces you to various API protocols such as XML-RPC, SOAP, and REST. You can programmatically ask any website or web service for information and interact with them. For example, you can search for products on Amazon or Google.
Chapter 18, Network Monitoring and Security, introduces you to various techniques for capturing, storing, analyzing, and manipulating network packets. This encourages you to go further to investigate your network security issues using concise Python scripts.
Chapter 19, Network Modeling, introduces you to the world of network simulations and emulations. You learn to simulate networks with NS-3, and emulate networking systems with Mininet and its extensions.
Chapter 20, Authentication, Authorization, and Accounting (AAA), introduces how the networks are secured, and discusses configuring LDAP clients with Python, accounting aspects of the network, and authentication and access of network services.
Chapter 21, Open and Proprietary Networking Solutions, discusses in detail, configuring largescale enterprise networking projects, including a few projects from Cisco, Juniper, VMware, and the Linux Foundation.
Chapter 22, NFV and Orchestration – A Larger Ecosystem, discusses configuring complex NFV and orchestration systems of the Linux Foundation, such as OPNFV, DPDK, SNAS.io, Dronekit, and PNDA. We elaborate the use of Python in these complex systems.
Chapter 23, Programming the Internet, presents you various Python libraries for BGP protocol and implementations developed for the internet scale. We learn to use and benchmark libraries such as exabgp and yabgp, and also discuss the looking glass implementations with Python.
To get the most out of this book
To get the most out of this book, some basic hands-on network operation knowledge and Python is recommended. Most of the chapters can be read in any order, with the exceptions of chapters 7 and 8, which should be read in sequence. Besides the basic software and hardware tools introduced at the beginning of the book, new tools relevant to each of the chapters will be introduced.
The hardware and software requirements for this book are Python (3.5 onward), Windows, Linux, an Ansible installation, and GNS3 (for testing) or real routers.
You need an internet connection for downloading the Python libraries. Also, basic knowledge of Python and networking is required.
Download the example code files
You can download the example code files for this book from your account at www.packt.com. If you purchased this book elsewhere, you can visit www.packt.com/support and register to have the files emailed directly to you.
You can download the code files by following these steps:
- Log in or register at www.packt.com.
- Select the
SUPPORT
tab. - Click on
Code Downloads & Errata
. - Enter the name of the book in the
Search
box and follow the onscreen instructions.
Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:
- WinRAR/7-Zip for Windows
- Zipeg/iZip/UnRarX for Mac
- 7-Zip/PeaZip for Linux
The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Python-Network-Programming. In case there's an update to the code, it will be updated on the existing GitHub repository.
We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!
Download the color images
We also provide a PDF file that has color images of the screenshots/diagrams used in this book. You can download it here: https://www.packtpub.com/sites/default/files/downloads/9781788835466_ColorImages.pdf.
Conventions used
There are a number of text conventions used throughout this book.
CodeInText
: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: "The input()
method is used to get an input from the user."
A block of code is set as follows:
#PowerShell sample code: $countries="India","UK","USA","France" foreach ($country in $countries) { write-host ($country+" is good") }
Any command-line input or output is written as follows:
easy_install <name of module>
Bold: Indicates a new term, an important word, or words that you see onscreen. For example, words in menus or dialog boxes appear in the text like this. Here is an example: "If you need something different, click on the DOWNLOADS link in the header for all possible downloads:"
Note
Warnings or important notes appear like this.
Note
Tips and tricks appear like this.
Get in touch
Feedback from our readers is always welcome.
General feedback: If you have questions about any aspect of this book, mention the book title in the subject of your message and email us at [email protected]
.
Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packt.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.
Piracy: If you come across any illegal copies of our works in any form on the Internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected]
with a link to the material.
If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.
Reviews
Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions, we at Packt can understand what you think about our products, and our authors can see your feedback on their book. Thank you!
For more information about Packt, please visit packt.com.