Following code works . My question is can I make it faster ? def activeip(checkip): # if there is any line returned we set activeb to 1 indicating that # this ip is active during a netstat run activeb=0 for line in os.popen("netstat -a -n | grep '%s'" % checkip) : s=line if s <>'' : activeb=1 return activeb Thanks