August 2017
Beginner
450 pages
13h 21m
English
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 + ":" ...