0%

Book Description

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.

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.

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

Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

Table of Contents

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