Python Network Programming Cookbook
Format: PDF / Kindle (mobi) / ePub
Over 70 detailed recipes to develop practical solutions for a wide range of realworld network programming tasks
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.
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
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.
A few things. First, our ThreadedTCPServer will inherit from TCPServer and TheadingMixIn. This multi-threaded version will launch a new thread when a client connects to it. Some more details can be found at http://docs.python.org/2/library/socketserver.html. The request handler class of our socket server, ForkingServerRequestHandler, sends the echo back to the client from a new thread. You can check the thread information here. For the sake of simplicity, we put the client code in a function.
File = http.getfile() return file.read() if __name__ == "__main__": parser = argparse.ArgumentParser(description='HTTP Client Example') parser.add_argument('--host', action="store", dest="host", default=REMOTE_SERVER_HOST) parser.add_argument('--path', action="store", dest="path", default=REMOTE_SERVER_PATH) given_args = parser.parse_args() host, path = given_args.host, given_args.path client = HTTPClient(host) print client.fetch(path) This recipe will by default fetch a page from.
On your machine, you need to install a local mail server such as postfix. On a Debian/Ubuntu system, this can be installed with default settings using apt-get, as shown in the following command: $ sudo apt-get install postfix 111 E-mail Protocols, FTP, and CGI Programming How to do it... Let us first compress the current directory and then create an e-mail message. We can send the e-mail message via an external SMTP host, or we can use a local e-mail server to do this. Like other recipes, let.
By giving it just the name of that city. You may not be interested in installing any third-party libraries for this simple task. How to do it... In this simple screen-scraping example, we use the Google Maps URL to query the latitude and longitude of a city. The URL used to query can be found after making a custom search on the Google Maps page. We can perform the following steps to extract some information from Google Maps. Let us take the name of a city from the command line using the argparse.
A minimal Supervisor configuration, as shown: [unix_http_server] file=/tmp/supervisor.sock chmod=0700 ; (the path to the socket file) ; socket file mode (default 0700) [supervisord] logfile=/tmp/supervisord.log loglevel=info 170 Chapter 8 pidfile=/tmp/supervisord.pid nodaemon=true [rpcinterface:supervisor] supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_ rpcinterface [program:8_2_multithreaded_multicall_xmlrpc_server.py] command=python.