Why ping all times alive?
<p>I scripting script which in log write ping alive or no alive.</p>

<p>But all times to log write that ping alive.</p>

<p>Why?</p>

<p>Code:</p>

<pre><code>import os
import re
import time
import sys
from threading import Thread
from time import gmtime, strftime

class IntTools:
    def PingTool(self):
        ipconf = open('ip.conf', 'r')
        ipstrip = ipconf.readlines()
        ip = ipstrip[2].strip()
        ip2 = ipstrip[3].strip()
        ip3 = ipstrip[4].strip()
        ip4 = ipstrip[5].strip()
        ip5 = ipstrip[6].strip()


        class testit(Thread):
            def __init__ (self,ip):
                Thread.__init__(self)
                self.ip = ip
                self.status = -1
            def run(self):
                pingaling = os.popen("ping "+self.ip+" -n 1","r")
                while 1:
                    line = pingaling.readline()
                    #print line
                    if not line: break
                    igot = re.findall(testit.lifeline,line)
                    if igot:
                        self.status = int(igot[0])

        testit.lifeline = re.compile(r"(\d) received")
        report = ("No response","Partial Response","Alive") 

        print time.ctime()  
        pinglist = []
        current = testit(ip)
        pinglist.append(current)
        current.start()
        for pingle in pinglist:
            pingle.join()
            pinglog = open('ping.log', 'a')
            pinglog.write('Status from '+pingle.ip+" is "+report[pingle.status]+'\n')
            pinglog.close()     
    def ReadPingLog(self):
        pinglog = open('ping.log', 'r+')
        print pinglog.read()
        pinglog.close()
IntTools = IntTools()
IntTools.PingTool()
</code></pre>
