def initialize(self): self.hostname = get_hostname() self.cycle = None self.dests = DestList() self.startCycle = 0 self.RAW_DIR = self.shared.parameters.RAW_DIR self.STATS_DIR = self.shared.parameters.STATS_DIR self.SAVE_RAW_TRACES = self.shared.parameters.SAVE_RW
def preload_destinations(self, _increment=False): try: log = logging.getLogger("agent.ping_cycle.preload") self.dests = DestList() #file_dest = open(self.iplist_file,'r') with open('iplist.dat') as f: self.destination = [line.rstrip() for line in f] try: for dest_ip in self.destination: #if dest_id == self.hostname: self.shared.check_killed( "Sender", self.shared.sender.event ) # check Sendere received killing signal. if self.UPPER_LIMIT != -1 and self.nDests > self.UPPER_LIMIT - 1: break index = dest_ip.find("/") try: if index != -1: # is it a subnet? socket.inet_aton( dest_ip[:index]) # check ip_validity net = self.networkMask( dest_ip[:index], int(dest_ip[(index + 1):])) # get subnet address addr = net + 1 # JUMP subnet address while self.addressInNetwork( addr, net, int(dest_ip[(index + 1):]) ) and (self.UPPER_LIMIT == -1 or (self.UPPER_LIMIT != -1 and self.nDests < self.UPPER_LIMIT - 1) ): # is IP into subnet? if self.nDests >= self.LOWER_LIMIT - 1: self.dests.insert( self.numToDottedQuad(addr)) self.nDests += 1 addr += 1 if self.addressInNetwork( addr, net, int(dest_ip[(index + 1):])) == False: if self.nDests >= self.LOWER_LIMIT - 1: self.dests.remove_last( ) # JUMP broadcast address self.nDests -= 1 # correct self.nDests else: if self.nDests >= self.LOWER_LIMIT - 1: addr = socket.gethostbyname( dest_ip ) # CHECK VALIDITY and (if necessary) convert NAME into IP self.dests.insert( addr ) #-------------------> problem: takes a lot of time socket.gethostbyname(dest_ip) self.nDests += 1 except socket.error: if index != -1: log.error("Invalid IP: %s" % dest_ip[:index]) else: log.error("Invalid IP: %s" % dest_ip) #-------------------------------------------------for testing #b=time.time()-a # a time.time before try #if time.time()-a>1: # print dest_ip # print b #-------------------------------------------------for testing self.nDests = self.nDests - max(self.LOWER_LIMIT, 1) + 1 log.info("Loaded targets: %d" % self.nDests) except why: #eliminare tutto i csv log.error( "TracerouteCycle::preload_destinations(): file %s, %s" % (self.iplist_file, why)) except Exception, why: log.error("Exception preload destination:") log.error(why)