Free Sample
+ Collection

Python Network Programming Cookbook

Cookbook
Dr. M. O. Faruque Sarker

This guide embraces the elegance and versatility of Python to assist any programmer or administrator who wants to create bespoke client/server networking applications using third-party libraries. Simply packed with recipes.
$26.99
$44.99
RRP $26.99
RRP $44.99
eBook
Print + eBook

Want this title & more?

$12.99 p/month

Subscribe to PacktLib

Enjoy full and instant access to over 2000 books and videos – you’ll find everything you need to stay ahead of the curve and make sure you can always get the job done.

Book Details

ISBN 139781849513463
Paperback234 pages

About This Book

  • Demonstrates how to write various besopke client/server networking applications using standard and popular third-party Python libraries
  • Learn how to develop client programs for networking protocols such as HTTP/HTTPS, SMTP, POP3, FTP, CGI, XML-RPC, SOAP and REST
  • Provides practical, hands-on recipes combined with short and concise explanations on code snippets

Who This Book Is For

If you are a network programmer, system/network administrator, or a web application developer, this book is ideal for you. You should have a basic familiarity with the Python programming language and TCP/IP networking concepts. However if you are a novice, you will develop an understanding of the concepts as you progress with this book. This book will serve as a supplementary material for developing hands-on skills in any academic course on network programming.

Table of Contents

Chapter 1: Sockets, IPv4, and Simple Client/Server Programming
Introduction
Printing your machine's name and IPv4 address
Retrieving a remote machine's IP address
Converting an IPv4 address to different formats
Finding a service name, given the port and protocol
Converting integers to and from host to network byte order
Setting and getting the default socket timeout
Handling socket errors gracefully
Modifying socket's send/receive buffer sizes
Changing a socket to the blocking/non-blocking mode
Reusing socket addresses
Printing the current time from the Internet time server
Writing a SNTP client
Writing a simple echo client/server application
Chapter 2: Multiplexing Socket I/O for Better Performance
Introduction
Using ForkingMixIn in your socket server applications
Using ThreadingMixIn in your socket server applications
Writing a chat server using select.select
Multiplexing a web server using select.epoll
Multiplexing an echo server using Diesel concurrent library
Chapter 3: IPv6, Unix Domain Sockets, and Network Interfaces
Introduction
Forwarding a local port to a remote host
Pinging hosts on the network with ICMP
Waiting for a remote network service
Enumerating interfaces on your machine
Finding the IP address for a specific interface on your machine
Finding whether an interface is up on your machine
Detecting inactive machines on your network
Performing a basic IPC using connected sockets (socketpair)
Performing IPC using Unix domain sockets
Finding out if your Python supports IPv6 sockets
Extracting an IPv6 prefix from an IPv6 address
Writing an IPv6 echo client/server
Chapter 4: Programming with HTTP for the Internet
Introduction
Downloading data from an HTTP server
Serving HTTP requests from your machine
Extracting cookie information after visiting a website
Submitting web forms
Sending web requests through a proxy server
Checking whether a web page exists with the HEAD request
Spoofing Mozilla Firefox in your client code
Saving bandwidth in web requests with the HTTP compression
Writing an HTTP fail-over client with resume and partial downloading
Writing a simple HTTPS server code with Python and OpenSSL
Chapter 5: E-mail Protocols, FTP, and CGI Programming
Introduction
Listing the files in a remote FTP server
Uploading a local file to a remote FTP server
E-mailing your current working directory as a compressed ZIP file
Downloading your Google e-mail with POP3
Checking your remote e-mail with IMAP
Sending an e-mail with an attachment via Gmail SMTP server
Writing a guestbook for your (Python-based) web server with CGI
Chapter 6: Screen-scraping and Other Practical Applications
Introduction
Searching for business addresses using the Google Maps API
Searching for geographic coordinates using the Google Maps URL
Searching for an article in Wikipedia
Searching for Google stock quote
Searching for a source code repository at GitHub
Reading news feed from BBC
Crawling links present in a web page
Chapter 7: Programming Across Machine Boundaries
Introduction
Executing a remote shell command using telnet
Copying a file to a remote machine by SFTP
Printing a remote machine's CPU information
Installing a Python package remotely
Running a MySQL command remotely
Transferring files to a remote machine over SSH
Configuring Apache remotely to host a website
Chapter 8: Working with Web Services – XML-RPC, SOAP, and REST
Introduction
Querying a local XML-RPC server
Writing a multithreaded multicall XML-RPC server
Running an XML-RPC server with a basic HTTP authentication
Collecting some photo information from Flickr using REST
Searching for SOAP methods from an Amazon S3 web service
Searching Google for custom information
Searching Amazon for books through product search API
Chapter 9: Network Monitoring and Security
Introduction
Sniffing packets on your network
Saving packets in the pcap format using the pcap dumper
Adding an extra header in HTTP packets
Scanning the ports of a remote host
Customizing the IP address of a packet
Replaying traffic by reading from a saved pcap file
Scanning the broadcast of packets

What You Will Learn

  • Develop TCP/IP networking client/server applications
  • Administer local machines' IPv4/IPv6 network interfaces
  • Write multi-purpose efficient web clients for HTTP and HTTPS protocols
  • Create e-mail clients to work with common e-mail protocols such as SMTP, POP3, IMAP, and so on.
  • Scrape websites and search for useful information
  • Perform remote system administration tasks over Telnet and SSH connections
  • Interact with popular websites via web services such as XML-RPC, SOAP, and REST APIs
  • Monitor and analyze major common network security vulnerabilities

In Detail

Python is an excellent language to use to write code and have fun by prototyping applications quickly. The presence of lots of third-party libraries, also known as batteries, makes it even more easier and faster to prototype an application or to implement a new algorithm. If you are interested in creating the building blocks for many practical web and networking applications that rely on networking protocols then this book is a must-have.

This book highlights major aspects of network programming in Python starting from writing simple networking clients, to developing complex screen-scraping and network security monitoring scripts. It creates the building blocks for many practical web and networking applications that rely on various networking protocols. This book presents the power and beauty of Python in solving the numerous real-world tasks in the area of network programming, system and network administration, network monitoring, and web-application development.

This book develops your ability to solve a wide range of network programming tasks in Python. We will start by exploring the Python standard library functions to create client/server network and manipulate your local networking resources available under both IPv4 and IPv6. The practical focus continues with creating web and email clients, scraping web pages, fetching information from various websites, and searching for information on the Web such as Amazon, Flickr, and other sites. It further develops your skills to analyze your network security vulnerabilities using advanced network packet capture and analysis techniques.

Authors

Read More

Recommended for You

Learning Python Data Visualization
$ 28.99