def __repr__(self): repr_ = ( '<IPv4Header| src: %s, dst: %s, proto: %s paylen: %d>' % (ip_to_string(self.src), ip_to_string(self.dst), ip_proto_to_string(self.protocol), self.length - self.ihl * 4)) if self.payload: repr_ += '\n %s' % repr(self.payload) return repr_
def __repr__(self): repr_ = ('<IPv4Header| src: %s, dst: %s, proto: %s paylen: %d>' % (ip_to_string(self.src), ip_to_string(self.dst), ip_proto_to_string(self.protocol), self.length - self.ihl * 4)) if self.payload: repr_ += '\n %s' % repr(self.payload) return repr_
def dns_recursion(dns_retriever: DnsRetriever, message: DnsMessage, ip_addrs: list, fixed: dict): if len(ip_addrs) == 0: return None for ip_addr in ip_addrs: if (ip_addr, message.questions[0]) in fixed: continue fixed[(ip_addr, message.questions[0])] = 1 response = dns_retriever.get_response(message, ip_addr) print("Asking {:30} about {:30s} {:5s} {:7s}".format(ip_addr, message.questions[0].name.decode( "ascii"), "IN", DnsMessage.codes[ message.questions[0].type])) print(response) if not response: continue if response.answer_count > 0: return response auth_servers = get_auth_servers_by_priority( response, dns_retriever) for aut_server in auth_servers: name = aut_server.data if aut_server.type != DnsMessage.NS: continue ips_with_ttl = dns_retriever.get_list_by_key((name, DnsMessage.A)) ips_lst = [] for ttl, ip in ips_with_ttl: ips_lst.append(ip_to_string(ip)) if len(ips_lst) > 0: ans = dns_recursion(dns_retriever, message, ips_lst, fixed) if ans: return ans else: data = copy.copy(message.data) lst = get_ips_for_NS( dns_retriever, dns_retriever.get_best_NS_servers(name)) lst.append(dns_retriever.get_root_server()) data = data[: message.questions_offset] + get_labels_from_string(name) + data[ message.questions_name_end:] cur_response = dns_recursion(dns_retriever, DnsMessage(data), lst, fixed) lst_with_ttl = dns_retriever.get_list_by_key((name, DnsMessage.A)) lst = [] for item in lst_with_ttl: lst.append(ip_to_string(item[1])) ans = dns_recursion(dns_retriever, message, lst, fixed) if ans: return ans
def get_ips_for_NS(dns_retriever: DnsRetriever, ns_list: list): lst = [] for ns in ns_list: cur_ans = dns_retriever.get_list_by_key((ns, DnsMessage.A)) for item in cur_ans: lst.append(ip_to_string(item[1])) return lst
def get_additional_answers(response: DnsMessage): additional_records = {} for additional_answer in response.additional: if additional_answer.type == DnsMessage.A: additional_records[additional_answer.name] = ip_to_string( additional_answer.data) return additional_records
def cache_ips(self, domain_name: bytes, response: DnsMessage): if domain_name not in self.ip_cache: self.ip_cache[domain_name] = [] for cur_answer in response.answers: if cur_answer.type == DnsMessage.A: self.ip_cache[domain_name].append( {"expiration_date": time.time() + cur_answer.ttl, "ip": ip_to_string(cur_answer.data)})
def __repr__(self): return ('<Datagram| src: %s: %d, agent: %s(%d), seq: %d, uptime: %dh>' % (self.src_addr, self.src_port, ip_to_string(self.agent_addr), self.sub_agent_id, self.sequence_number, floor(self.uptime/3600000.0)))
def __repr__(self): return ( '<Datagram| src: %s: %d, agent: %s(%d), seq: %d, uptime: %dh>' % (self.src_addr, self.src_port, ip_to_string( self.agent_addr), self.sub_agent_id, self.sequence_number, floor(self.uptime / 3600000.0)))