Cover; Copyright; Credits; About the Authors; About the Reviewers; www.PacktPub.com; Table of Contents; Preface; Chapter 1: Network Programming and Python; An introduction to TCP/IP networks; IP addresses; Network Interfaces; Assigning IP addresses; IP addresses on the Internet; Packets; Networks; Routing with IP; DNS; The protocol stack or why the Internet is like a cake; Layer 4 - TCP and UDP; Network ports; UDP; TCP; UDP versus TCP; Layer 5 - The application layer; On to Python!; Network programming with Python; Breaking a few eggs; Taking it from the top; Downloading an RFC. Looking deeperProgramming for TCP/IP networks; Firewalls; Network Address Translation; IPv6; Summary; Chapter 2: HTTP and Working with the Web; Request and response; Requests with urllib; Response objects; Status codes; Handling problems; HTTP headers; Customizing requests; Content compression; Multiple values; Content negotiation; Content types; User agents; Cookies; Cookie handling; Know your cookies; Redirects; URLs; Paths and relative URLs; Query strings; URL encoding; URLs in summary; HTTP methods; The HEAD method; The POST method; Formal inspection; HTTPS; The Requests library. Handling errors with RequestsSummary; Chapter 3: APIs in Action; Getting started with XML; The XML APIs; The basics of ElementTree; Pretty printing; Element attributes; Converting to text; The Amazon S3 API; Registering with AWS; Authentication; Setting up an AWS user; Regions; S3 buckets and objects; An S3 command-line client; Creating a bucket with the API; Uploading a file; Retrieving an uploaded file through a web browser; Displaying an uploaded file in a web browser; Downloading a file with the API; Parsing XML and handling errors; Parsing XML; Finding elements; Handling errors. Further enhancementsThe Boto package; Wrapping up with S3; JSON; Encoding and decoding; Using dicts with JSON; Other object types; The Twitter API; A Twitter world clock; Authentication for Twitter; Registering your application for the Twitter API; Authenticating requests; A Twitter client; Polling for Tweets; Processing the tweets; Rate limits; Sending a reply; Final touches; Taking it further; Polling and the Twitter streaming APIs; Alternative oAuth flows; HTML and screen scraping; HTML parsers; Show me the data; Parsing HTML with lxml; Zeroing in; Searching with XPath; XPath conditions. Pulling it togetherWith great power ... ; Choosing a User Agent; The Robots.txt file; Summary; Chapter 4: Engaging with E-mails; E-mail terminologies; Sending e-mails with SMTP; Composing an e-mail message; Sending an e-mail message; Sending e-mails securely with TLS; Retrieving e-mails by using POP3 with poplib; Retrieving e-mails by using IMAP with imaplib; Sending e-mail attachments; Sending e-mails via the logging module; Summary; Chapter 5: Interacting with Remote Systems; Secure shell - access using Python; Inspecting the SSH packets; Transferring files through SFTP. Transferring files with FTP. 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. Basic knowledge of Python is assumed. Read more... Abstract: Cover; Copyright; Credits; About the Authors; About the Reviewers; www.PacktPub.com; Table of Contents; Preface; Chapter 1: Network Programming and Python; An introduction to TCP/IP networks; IP addresses; Network Interfaces; Assigning IP addresses; IP addresses on the Internet; Packets; Networks; Routing with IP; DNS; The protocol stack or why the Internet is like a cake; Layer 4 - TCP and UDP; Network ports; UDP; TCP; UDP versus TCP; Layer 5 - The application layer; On to Python!; Network programming with Python; Breaking a few eggs; Taking it from the top; Downloading an RFC. Looking deeperProgramming for TCP/IP networks; Firewalls; Network Address Translation; IPv6; Summary; Chapter 2: HTTP and Working with the Web; Request and response; Requests with urllib; Response objects; Status codes; Handling problems; HTTP headers; Customizing requests; Content compression; Multiple values; Content negotiation; Content types; User agents; Cookies; Cookie handling; Know your cookies; Redirects; URLs; Paths and relative URLs; Query strings; URL encoding; URLs in summary; HTTP methods; The HEAD method; The POST method; Formal inspection; HTTPS; The Requests library. Handling errors with RequestsSummary; Chapter 3: APIs in Action; Getting started with XML; The XML APIs; The basics of ElementTree; Pretty printing; Element attributes; Converting to text; The Amazon S3 API; Registering with AWS; Authentication; Setting up an AWS user; Regions; S3 buckets and objects; An S3 command-line client; Creating a bucket with the API; Uploading a file; Retrieving an uploaded file through a web browser; Displaying an uploaded file in a web browser; Downloading a file with the API; Parsing XML and handling errors; Parsing XML; Finding elements; Handling errors. Further enhancementsThe Boto package; Wrapping up with S3; JSON; Encoding and decoding; Using dicts with JSON; Other object types; The Twitter API; A Twitter world clock; Authentication for Twitter; Registering your application for the Twitter API; Authenticating requests; A Twitter client; Polling for Tweets; Processing the tweets; Rate limits; Sending a reply; Final touches; Taking it further; Polling and the Twitter streaming APIs; Alternative oAuth flows; HTML and screen scraping; HTML parsers; Show me the data; Parsing HTML with lxml; Zeroing in; Searching with XPath; XPath conditions. Pulling it togetherWith great power ... ; Choosing a User Agent; The Robots.txt file; Summary; Chapter 4: Engaging with E-mails; E-mail terminologies; Sending e-mails with SMTP; Composing an e-mail message; Sending an e-mail message; Sending e-mails securely with TLS; Retrieving e-mails by using POP3 with poplib; Retrieving e-mails by using IMAP with imaplib; Sending e-mail attachments; Sending e-mails via the logging module; Summary; Chapter 5: Interacting with Remote Systems; Secure shell - access using Python; Inspecting the SSH packets; Transferring files through SFTP. Transferring files with FTP. 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. Basic knowledge of Python is assumed Utilize Python 3 to get network applications up and running quickly and easily About This BookLeverage your Python programming skills to build powerful network applicationsExplore steps to interact with a wide range of network servicesDesign multithreaded and event-driven architectures for echo and chat serversWho This Book Is ForIf 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. Basic knowledge of Python is assumed. What You Will LearnDevelop an understanding of network stacks and the power of encapsulationDesign high-performance network server applicationsImplement socket-based network applications using asynchronous modelsBuild client applications for major web APIs, including Amazon S3 and TwitterInteract with e-mail servers using SMTP, POP3, and IMAP protocolsDeal with remote network servers using SSH, FTP, SNMP, SMB/CIFS, and LDAP protocolsWork with IP addresses including Geo-IP lookupsDownload objects from the Web and craft custom HTTP requests with urllib and the Requests libraryIn DetailNetwork 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 walkthrough of today's major networking protocols, with 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'll utilize Python for e-mailing using different protocols and you'll interact with remote systems and IP and DNS networking. 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 client-side applications, including web API clients, e-mail clients, SSH, and FTP. These applications will also be implemented through existing web application frameworks.