def handle_read(self): logging.root.debug("Handling Read") finishtime = int(round(time.time() * 1000)) data, addr = self.sock.recvfrom(4096) recvIP = IP.disassemble(data) recvICMP = ICMPHeader.disassemble(recvIP.data) retnIP = IP.disassemble(recvICMP.data) if retnIP.ident in self.eventloop.probes: self.eventloop.probes[retnIP.ident](recvICMP, retnIP.ident, finishtime)
def binary_search(self, icmp, ident, finishtime): """Binary Search takes raw packet data, and searches for the proper number of hops to a particular router. data = the raw ip packet """ if self.ident == ident: if icmp.type == 3: ip = IP.disassemble(icmp.data) ttl = self.current_ttl - ip.ttl + 1 rtt = finishtime - self.starttime log_str = '%s: HOPS=%d, RTT=%d' % (self.destaddr[0], ttl, rtt) logging.root.info(log_str) if self.output: self.output.write('%s, %d, %d\n' % (self.destaddr[0], ttl, rtt)) self.handle_close() elif icmp.type == 11: logging.root.debug('TTL Estimate Too Low') self.current_ttl = self.current_ttl*2 self.create_packet() log_str = 'Changing TTL: %s' % self.current_ttl logging.root.info(log_str) else: log_str = 'Unknown ICMP Type=%d, Code=%d' % (icmp.type, icmp.code) logging.root.info(log_str) self.current_ttl = self.current_ttl*2 self.create_packet() log_str = 'Changing TTL: %s' % self.current_ttl logging.root.info(log_str)