Skip to Content
Python Network Programming Cookbook - Second Edition
book

Python Network Programming Cookbook - Second Edition

by Pradeeban Kathiravelu, Dr. M. O. Faruque Sarker
August 2017
Beginner
450 pages
13h 21m
English
Packt Publishing
Content preview from Python Network Programming Cookbook - Second Edition

How to do it...

Here we will look into a simple recipe that performs this action, as indicated by listing 14.1:

#!/usr/bin/env python 
# Python Network Programming Cookbook, Second Edition  -- Chapter - 14 
# This program is optimized for Python 2.7.12 and  Python 3.5.2. 
# It may run on any other version with/without modifications. 
  
import socket 
from sys import stdout 
from time import sleep 
import argparse 
  
def is_alive(address, port): 
    # Create a socket object to connect with 
    s = socket.socket() 
     
    # Now try connecting, passing in a tuple with address & port try: s.connect((address, port)) return True except socket.error: return False finally: s.close() def confirm(addres, port): while True: if is_alive(address, port): stdout.write(address + ":" ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Python Network Programming

Python Network Programming

Abhishek Ratan, Eric Chou, Pradeeban Kathiravelu, Dr. M. O. Faruque Sarker

Publisher Resources

ISBN: 9781786463999Supplemental Content