D&C Lug - Home Page
Devon & Cornwall Linux Users' Group

[ Date Index ][ Thread Index ]
[ <= Previous by date / thread ] [ Next by date / thread => ]

Re: [LUG] Testing an open socket



On Wed, Jul 10, 2002 at 03:18:21PM +0100, John Horne wrote:
yet. Anyone done anything like this and know of a better way to test the 
socket?

#!/usr/bin/python
import socket

HOST = 'localhost'
PORT = 80
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
       s.connect((HOST, PORT))
       alive = 1
except:
       alive = 0

s.close()
if alive == 1:
       print `PORT` + ' alive!'
else:   print `PORT` + ' dead :('


"""
Here is how I would test a socket in python. Simple eh?

python rules !

-Kai
"""

Attachment: scanner.py
Description: Text document


Lynx friendly