예제 #1
0
 def work(self):
     """
     Main working routine
     Here is the protocol:
     
     Repeat every <refresh> seconds:
     1. load new proxy configuration file
     2. test each proxy, filter out the good ones
     3. generate new config file from template file
     4. test new config file with squid parse, if is OK, reload squid
     """
     phaseStartTime = time.time()
     phaseStartDatetime = datetime.datetime.now()
     desc = ''
     
     problem2send= ''
     timeReported=False
     phaseCurTime = 0
     phaseCurDatetime = datetime.datetime.now()
     phunt = proxyhunter(OutputProxy='proxylist.txt', GoodProxy='goodproxylist.txt', 
             Verbose=False, TimeOut=int(self.proxytimeout), 
             Sitelist=[], RetryCount=int(self.proxyretry), 
             TestUrl=self.proxyurl)
     prevHash=None
     prevConfigHash=None
     
     desc += "* Starting daemon on %s (sec: %s)\n" % (phaseStartDatetime.strftime("%Y-%m-%d %H:%M"), phaseStartTime)
     print desc
     while True:
         time.sleep(10)
         proxylist = []
         try:
             preventstrokes = open(self.proxysrc, "r")
             proxylist      = preventstrokes.readlines()
             preventstrokes.close()
         except Exception, e:
             print "Error during reading proxy source file [%s]: " % self.proxysrc, e
             traceback.print_exc()
             continue
         
         md5 = hashlib.md5()
         md5.update(str(proxylist))
         newHash = md5.hexdigest()
         
         # nothing to do, file is same or too fresh from last check
         if newHash == prevHash and (time.time() - phaseCurTime) <= float(self.proxyrefresh):
             continue
         
         prevHash = newHash
         phaseCurTime = time.time()
         phaseCurDatetime = datetime.datetime.now()
         curProxyList = self.readProxyList(proxylist)
         
         outDat  = "* Starting check on %s (sec: %s)\n" % (phaseCurDatetime, phaseCurTime)
         outDat += "* Proxies to check: %d\n" % (len(curProxyList))
         cnOK=0
         cnFail=0
         for i,p in enumerate(copy.deepcopy(curProxyList)):
             tmpProxyName=''
             if len(p)==2:
                 tmpProxyName=str(p[0]) + ":" + str(p[1])
             elif len(p)==4:
                 tmpProxyName=str(p[2]) + ":" + str(p[3]) + "@" + str(p[0]) + ":" + str(p[1])
             else:
                 curProxyList.remove(p)
                 
             '''Proxy test and remove failures'''
             cProxyStart = time.time()
             cProxyRes = phunt.CoreFreshTester(tmpProxyName)
             cProxyTime = time.time()-cProxyStart 
             if cProxyRes:
                 cnFail+=1
                 print     "[*] %s%s%s \n \'--------------> Piece of Shit [%05.2f s]" % (phunt._red, tmpProxyName, phunt._reset, cProxyTime)
                 outDat += "[*] %s \n \'--------------> Piece of Shit [%05.2f s]\n" % (tmpProxyName, cProxyTime)
                 curProxyList.remove(p)
             else:
                 cnOK+=1
                 outDat += "[*] %s \n \'--------------> We have a Good One [%05.2f s]\n" % (tmpProxyName, cProxyTime)
                 print     "[*] %s%s%s \n \'--------------> We have a Good One [%05.2f s]" % (phunt._red, tmpProxyName, phunt._reset, cProxyTime)
         pass
         
         '''Dump check to file, if required'''
         if self.reportfile!=None:
             outDat += "Good proxies vs. shity proxies: %d vs. %d\n" % (cnOK, cnFail)
             try:
                 rH = open(self.reportfile, 'w')
                 rH.write(outDat)
                 rH.close()
             except Exception, e:
                 print "Cannot write to dump file [%s]" % self.reportfile, e
                 traceback.print_exc()
예제 #2
0
 def work(self):
     """
     Main working routine
     Here is the protocol:
     
     Repeat every <refresh> seconds:
     1. load new proxy configuration file
     2. test each proxy, filter out the good ones
     3. generate report
     """
     phaseStartTime = time.time()
     phaseStartDatetime = datetime.datetime.now()
     desc = ''
     
     problem2send= ''
     timeReported=False
     phaseCurTime = time.time()
     phaseCurDatetime = datetime.datetime.now()
     
     desc += "* Starting daemon on %s (sec: %s)\n" % (phaseStartDatetime.strftime("%Y-%m-%d %H:%M"), phaseStartTime)
     print desc
     
     prevHash = None
     while True:
         time.sleep(10)
         phunt = proxyhunter(OutputProxy='proxylist.txt', GoodProxy='goodproxylist.txt', 
                             Verbose=False, TimeOut=int(self.proxytimeout), 
                             Sitelist=[], RetryCount=int(self.proxyretry), 
                             TestUrl=self.proxyurl)
         curProxyList = self.readProxyList()
         
         md5 = hashlib.md5()
         md5.update(str(curProxyList))
         newHash = md5.hexdigest()
         if (newHash==prevHash):
             continue
         
         phaseStartDatetime = datetime.datetime.now()
         outDat = "* Starting check on %s (sec: %s)\n" % (phaseStartDatetime.strftime("%Y-%m-%d %H:%M"), phaseStartTime)
         prevHash=newHash
         for i,p in enumerate(copy.deepcopy(curProxyList)):
             tmpProxyName=''
             if len(p)==2:
                 tmpProxyName=str(p[0]) + ":" + str(p[1])
             elif len(p)==4:
                 tmpProxyName=str(p[2]) + ":" + str(p[3]) + "@" + str(p[0]) + ":" + str(p[1])
             else:
                 curProxyList.remove(p)
                 
             '''Proxy test and remove failures'''
             cProxyStart = time.time()
             cProxyRes = phunt.CoreFreshTester(tmpProxyName)
             cProxyTime = time.time()-cProxyStart 
             if cProxyRes:
                 outDat += "[*] %s \n \'--------------> Piece of Shit [%05.2f s]\n" % (tmpProxyName, cProxyTime)
             else:
                 outDat += "[*] %s \n \'--------------> We have a Good One [%05.2f s]\n" % (tmpProxyName, cProxyTime)
         pass
         print outDat
         
         '''Generate report'''
         try:
             tmpOutFileH = open(self.output, 'w')
             tmpOutFileH.write(outDat)
             tmpOutFileH.close()
         except Exception, e:
             print "Error during saving new configuration file: ", e
             continue