Book Review: Python Network Programming by Dr. M. O. Faruque Sarker with Examples

Python Network Programming Cookbook


Today I am tackling a book review. I saw an ad for the book on Google+ and I was able to get a free copy on Packt Publishing’s dime, in return I said I would write a review. I have a cursory knowledge of Python so I had to look a little bit more into what the language was all about before I dove head first into a book about advanced Python techniques. After a long stint on Codecademy I came out with a better understanding of the language and more confidence in my Python skills. Enough to dig into the book and get a lot out of it. So now lets get into this.

Quick note


I’d like to make a quick note: this post is simply a review of this book. This will not be a primer on Python, this post assumes that you know a little bit about python. It will also help if you have some knowledge of either network administration or back end development. I have been a little opportunistic here because I have been working with networks for a few years now. Awesome sauce!



So the book itself is not that long, about 211 pages. It justifies its price of $22.95 for the e-book edition with a small but substantive footprint. The lessons are short, sweet, and to the point. The author does not waste a lot of time explaining everything that goes into the code, only the parts that are introduced. The book also does not go into explanations about the Python syntax so people who are still new to Python may run screaming into the night (keyboards in hand refusing to accept the truth).

Even with shorter chapters the book is not short of things to talk about. Developers reading this without knowledge of networking may get a little caught up in some of the terms but the chapters are easy enough to read and follow along with even without a thorough understanding of Python (you can tell because I can follow it, and I am no where near an expert). It takes you through a lot of the steps into creating tools for networking, troubleshooting server issues, and creating back end tools for awesome websites!



If I were giving this book a grade I would have to give this book a strong B+! I give this that grade because it is a very specialized book, and it is not for every developer out there. That grade really comes from what my readership is. The things I write about really gravitate towards newer developers and trying to help them learn more about the web as a whole. If a newer developer is brave please try this book, if you can get through the first few chapters there is some awesome reading ahead.



I’m going to go through a simple example from the first chapter of the book. I learned how to create a script to display the network time in the Python console. Here this book is geared towards python 2.7, I have yet to test it on python 3. Below is the code and after it I will explain what I did.

First thing we want to do now that Python is installed we want to install a Python library known as ntplib (network time protocol library). We do this by running this command in the command line:

pip install ntplib

You are going to need pip installed for this to work. The command runs and ntplib is installed and now you can import the library from your python scripts.

Now that we have that installed we can create a new file called After we make this file we now add the following code:

import ntplib
from time import ctime

def print_time():
	ntp_client = ntplib.NTPClient()
	response = ntp_client.request('')
	print ctime(response.tx_time)

if __name__ == '__main__':

One thing that I really like about python is that at the top of the script you have to import the libraries that you need for the script, which for me is awesome because the scripts footprint (memory wise, and cpu cycle wise) is small. So we import ntplib and from that library we import the ctime module from ntplib library. The basic principle of ctime is to display the time. We then create a function to show our time called print_time(). We create a variable called ntp_client and use that to call the ntplib to call the NTPClient() command to create the instance, and then we create the response variable which requests the time from the url, in this instance We then use the ctime module to display the time.

After writing the code when we run it we get the response from the server at which displays the following line:

Mon Nov 10 20:46:50 2014

There we have it, the current time!

Final Word


Who this book is for:


This book is for Python developers, or developers that have python knowledge, who want to delve deeper into what the language can do for their web apps. Or the brave and bold developers with no Python experience.

Who this book is not for:


Newer developers with no experience with Python.

Buy Here


1 reply

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply