Constructing thread in Python
The thread can be constructed in the Python program.Just construct a program which requires a network connection and need to find the availability of computers in the network.
The code which will show you the position of the 10 computers in the network :
Code:
import os
import re
import time
import sys
lifeline = re.compile(r"(\d) received")
report = ("No response","Partial Response","Alive")
print time.ctime()
for hst in rng(60,70):
ip = "192.168.200."+str(hst)
pingaling = os.popen("ping -q -c2 "+ip,"r")
print "Testing ",ip,
sys.stdout.flush()
while 1:
line = pingaling.readline()
if not line: break
igot = re.findall(lifeline,line)
if igot:
print report[int(igot[0])]
print time.ctime()
Bookmarks