How to use to_text method in avocado

Best Python code snippet using avocado_python

dnshelper.py

Source:dnshelper.py Github

copy

Full Screen

...86 ipv4_answers = self._res.query(host_trg, 'A', tcp=tcp)87 for ardata in ipv4_answers.response.answer:88 for rdata in ardata:89 if rdata.rdtype == 5:90 if rdata.target.to_text().endswith('.'):91 address.append(["CNAME", host_trg, rdata.target.to_text()[:-1]])92 host_trg = rdata.target.to_text()[:-1]93 else:94 address.append(["CNAME", host_trg, rdata.target.to_text()])95 host_trg = rdata.target.to_text()96 else:97 address.append(["A", host_trg, rdata.address])98 except Exception:99 return address100 return address101 def get_aaaa(self, host_trg):102 """103 Function for resolving the AAAA Record for a given host. Returns an Array of104 the IP Address it resolves to. It will also return CNAME data.105 """106 address = []107 tcp = True if self._proto == "tcp" else False108 try:109 ipv6_answers = self._res.query(host_trg, 'AAAA', tcp=tcp)110 for ardata in ipv6_answers.response.answer:111 for rdata in ardata:112 if rdata.rdtype == 5:113 if rdata.target.to_text().endswith('.'):114 address.append(["CNAME", host_trg, rdata.target.to_text()[:-1]])115 host_trg = rdata.target.to_text()[:-1]116 else:117 address.append(["CNAME", host_trg, rdata.target.to_text()])118 host_trg = rdata.target.to_text()119 else:120 address.append(["AAAA", host_trg, rdata.address])121 except Exception:122 return address123 return address124 def get_ip(self, hostname):125 """126 Function resolves a host name to its given A and/or AAAA record. Returns Array127 of found hosts and IPv4 or IPv6 Address.128 """129 found_ip_add = []130 found_ip_add.extend(self.get_a(hostname))131 found_ip_add.extend(self.get_aaaa(hostname))132 return found_ip_add133 def get_mx(self):134 """135 Function for MX Record resolving. Returns all MX records. Returns also the IP136 address of the host both in IPv4 and IPv6. Returns an Array137 """138 mx_records = []139 tcp = True if self._proto == "tcp" else False140 answers = self._res.query(self._domain, 'MX', tcp=tcp)141 for rdata in answers:142 try:143 name = rdata.exchange.to_text()144 ipv4_answers = self._res.query(name, 'A', tcp=tcp)145 for ardata in ipv4_answers:146 if name.endswith('.'):147 mx_records.append(['MX', name[:-1], ardata.address,148 rdata.preference])149 else:150 mx_records.append(['MX', name, ardata.address,151 rdata.preference])152 except Exception:153 pass154 try:155 for rdata in answers:156 name = rdata.exchange.to_text()157 ipv6_answers = self._res.query(name, 'AAAA', tcp=tcp)158 for ardata in ipv6_answers:159 if name.endswith('.'):160 mx_records.append(['MX', name[:-1], ardata.address,161 rdata.preference])162 else:163 mx_records.append(['MX', name, ardata.address,164 rdata.preference])165 return mx_records166 except Exception:167 return mx_records168 def get_ns(self):169 """170 Function for NS Record resolving. Returns all NS records. Returns also the IP171 address of the host both in IPv4 and IPv6. Returns an Array.172 """173 name_servers = []174 tcp = True if self._proto == "tcp" else False175 answer = self._res.query(self._domain, 'NS', tcp=tcp)176 if answer is not None:177 for aa in answer:178 name = aa.target.to_text()[:-1]179 ip_addrs = self.get_ip(name)180 for addresses in ip_addrs:181 if re.search(r'^A', addresses[0]):182 name_servers.append(['NS', name, addresses[2]])183 return name_servers184 def get_soa(self):185 """186 Function for SOA Record resolving. Returns all SOA records. Returns also the IP187 address of the host both in IPv4 and IPv6. Returns an Array.188 """189 soa_records = []190 tcp = True if self._proto == "tcp" else False191 querymsg = dns.message.make_query(self._domain, dns.rdatatype.SOA)192 try:193 if tcp:194 response = dns.query.tcp(querymsg, self._res.nameservers[0], self._res.timeout)195 else:196 response = dns.query.udp(querymsg, self._res.nameservers[0], self._res.timeout)197 if len(response.authority) > 0:198 answers = response.authority199 elif len(response.answer) > 0:200 answers = response.answer201 else:202 return soa_records203 for rdata in answers:204 name = None205 if isinstance(rdata[0], dns.rdtypes.ANY.SOA.SOA):206 name = rdata[0].mname.to_text()207 else:208 continue209 if name:210 ipv4_answers = self._res.query(name, 'A', tcp=tcp)211 for ardata in ipv4_answers:212 if name.endswith('.'):213 soa_records.append(['SOA', name[:-1], ardata.address])214 else:215 soa_records.append(['SOA', name, ardata.address])216 except (dns.resolver.NXDOMAIN, dns.exception.Timeout, dns.resolver.NoAnswer, socket.error, dns.query.BadResponse):217 print_error('Error while resolving SOA record.')218 return soa_records219 try:220 for rdata in answers:221 name = None222 if isinstance(rdata, dns.rdtypes.ANY.SOA.SOA):223 name = rdata.mname.to_text()224 if name:225 ipv6_answers = self._res.query(name, 'AAAA', tcp=tcp)226 for ardata in ipv6_answers:227 if name.endswith('.'):228 soa_records.append(['SOA', name[:-1], ardata.address])229 else:230 soa_records.append(['SOA', name, ardata.address])231 return soa_records232 except Exception:233 return soa_records234 def get_spf(self):235 """236 Function for SPF Record resolving returns the string with the SPF definition.237 Prints the string for the SPF Record and Returns the string238 """239 spf_record = []240 tcp = True if self._proto == "tcp" else False241 try:242 answers = self._res.query(self._domain, 'SPF', tcp=tcp)243 for rdata in answers:244 name = bytes.join(b'', rdata.strings).decode('utf-8')245 spf_record.append(['SPF', name])246 except Exception:247 return None248 return spf_record249 def get_txt(self, target=None):250 """251 Function for TXT Record resolving returns the string.252 """253 txt_record = []254 tcp = True if self._proto == "tcp" else False255 if target is None:256 target = self._domain257 try:258 answers = self._res.query(target, 'TXT', tcp=tcp)259 for rdata in answers:260 string = bytes.join(b'', rdata.strings).decode('utf-8')261 txt_record.append(['TXT', target, string])262 except Exception:263 return []264 return txt_record265 def get_ptr(self, ipaddress):266 """267 Function for resolving PTR Record given it's IPv4 or IPv6 Address.268 """269 found_ptr = []270 tcp = True if self._proto == "tcp" else False271 n = dns.reversename.from_address(ipaddress)272 try:273 answers = self._res.query(n, 'PTR', tcp=tcp)274 for a in answers:275 if a.target.to_text().endswith('.'):276 found_ptr.append(['PTR', a.target.to_text()[:-1], ipaddress])277 else:278 found_ptr.append(['PTR', a.target.to_text(), ipaddress])279 return found_ptr280 except Exception:281 return None282 def get_srv(self, host):283 """284 Function for resolving SRV Records.285 """286 record = []287 tcp = True if self._proto == "tcp" else False288 try:289 answers = self._res.query(host, 'SRV', tcp=tcp)290 for a in answers:291 if a.target.to_text().endswith('.'):292 target = a.target.to_text()[:-1]293 else:294 target = a.target.to_text()295 ips = self.get_ip(target)296 if ips:297 for ip in ips:298 if re.search('(^A|AAAA)', ip[0]):299 record.append(['SRV', host, target, ip[2],300 str(a.port), str(a.weight)])301 else:302 record.append(['SRV', host, target, "no_ip",303 str(a.port), str(a.weight)])304 except Exception:305 return record306 return record307 def get_nsec(self, host):308 """309 Function for querying for a NSEC record and retrieving the rdata object.310 This function is used mostly for performing a Zone Walk against a zone.311 """312 tcp = True if self._proto == "tcp" else False313 answer = self._res.query(host, 'NSEC', tcp=tcp)314 return answer315 def from_wire(self, xfr, zone_factory=Zone, relativize=True):316 """317 Method for turning returned data from a DNS AXFR in to RRSET, this method will not perform a318 check origin on the zone data as the method included with dnspython319 """320 z = None321 for r in xfr:322 if z is None:323 if relativize:324 origin = r.origin325 else:326 origin = r.answer[0].name327 rdclass = r.answer[0].rdclass328 z = zone_factory(origin, rdclass, relativize=relativize)329 for rrset in r.answer:330 znode = z.nodes.get(rrset.name)331 if not znode:332 znode = z.node_factory()333 z.nodes[rrset.name] = znode334 zrds = znode.find_rdataset(rrset.rdclass, rrset.rdtype,335 rrset.covers, True)336 zrds.update_ttl(rrset.ttl)337 for rd in rrset:338 rd.choose_relativity(z.origin, relativize)339 zrds.add(rd)340 return z341 def zone_transfer(self):342 """343 Function for testing for zone transfers for a given Domain, it will parse the344 output by record type.345 """346 # if anyone reports a record not parsed I will add it, the list is a long one347 # I tried to include those I thought where the most common.348 zone_records = []349 ns_records = []350 print_status('Checking for Zone Transfer for {0} name servers'.format(self._domain))351 # Find SOA for Domain352 print_status("Resolving SOA Record")353 try:354 soa_srvs = self.get_soa()355 for s in soa_srvs:356 print_good("\t {0}".format(" ".join(s)))357 ns_records.append(s[2])358 except Exception:359 print_error("Could not obtain the domains SOA Record.")360 return361 # Find NS for Domain362 print_status("Resolving NS Records")363 try:364 ns_srvs = []365 ns_srvs = self.get_ns()366 print_status("NS Servers found:")367 for ns in ns_srvs:368 print_status("\t{0}".format(" ".join(ns)))369 ns_ip = ''.join(ns[2])370 ns_records.append(ns_ip)371 except Exception as e:372 print_error(f"Could not Resolve NS Records: {e}")373 # Remove duplicates374 print_status("Removing any duplicate NS server IP Addresses...")375 ns_records = list(set(ns_records))376 # Test each NS Server377 for ns_srv in ns_records:378 print_status(" ")379 print_status('Trying NS server {0}'.format(ns_srv))380 if self.check_tcp_dns(ns_srv):381 print_good('{0} Has port 53 TCP Open'.format(ns_srv))382 try:383 zone = self.from_wire(dns.query.xfr(ns_srv, self._domain))384 print_good('Zone Transfer was successful!!')385 zone_records.append({'type': 'info', 'zone_transfer': 'success', 'ns_server': ns_srv})386 for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.SOA):387 for rdata in rdataset:388 for mn_ip in self.get_ip(rdata.mname.to_text()):389 if re.search(r'^A', mn_ip[0]):390 print_status('\t SOA {0} {1}'.format(rdata.mname.to_text()[:-1], mn_ip[2]))391 zone_records.append({'zone_server': ns_srv, 'type': 'SOA',392 'mname': rdata.mname.to_text()[:-1], 'address': mn_ip[2]})393 for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.NS):394 for rdata in rdataset:395 # Check if target is only the host name or a full FQDN.396 # If only a hostname we will append the domain name of the397 # Zone being transfered.398 target = rdata.target.to_text()399 target_split = target.split('.')400 appended = False401 if len(target_split) == 1:402 target = target + '.' + self._domain403 appended = True404 for n_ip in self.get_ip(target):405 if re.search(r'^A', n_ip[0]):406 if appended:407 print_status('\t NS {0} {1}'.format(target, n_ip[2]))408 zone_records.append({'zone_server': ns_srv, 'type': 'NS',409 'target': target, 'address': n_ip[2]})410 else:411 if rdata.target.to_text().endswith('.'):412 target = rdata.target.to_text()[:-1]413 else:414 target = rdata.target.to_text()415 print_status('\t NS {0} {1}'.format(target, n_ip[2]))416 zone_records.append({'zone_server': ns_srv, 'type': 'NS',417 'target': target, 'address': n_ip[2]})418 for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.TXT):419 for rdata in rdataset:420 rdata = [string.decode() for string in rdata.strings]421 print_status('\t TXT {0}'.format(''.join(rdata)))422 zone_records.append({'zone_server': ns_srv, 'type': 'TXT',423 'strings': ''.join(rdata)})424 for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.SPF):425 for rdata in rdataset:426 print_status('\t SPF {0}'.format(''.join(rdata.strings)))427 zone_records.append({'zone_server': ns_srv, 'type': 'SPF',428 'strings': ''.join(rdata.strings)})429 for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.PTR):430 for rdata in rdataset:431 for n_ip in self.get_ip(rdata.target.to_text() + "." + self._domain):432 if re.search(r'^A', n_ip[0]):433 print_status('\t PTR {0} {1}'.format(rdata.target.to_text() + "." + self._domain, n_ip[2]))434 zone_records.append({'zone_server': ns_srv, 'type': 'PTR',435 'name': rdata.target.to_text() + "." + self._domain, 'address': n_ip[2]})436 for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.MX):437 for rdata in rdataset:438 for e_ip in self.get_ip(rdata.exchange.to_text()):439 if re.search(r'^A', e_ip[0]):440 if rdata.exchange.to_text().endswith('.'):441 exchange = rdata.exchange.to_text()[:-1]442 else:443 exchange = rdata.exchange.to_text()444 print_status('\t MX {0} {1} {2}'.format(str(name) + '.' + self._domain,445 exchange, e_ip[2]))446 zone_records.append({'zone_server': ns_srv, 'type': 'MX',447 'name': str(name) + '.' + self._domain,448 'exchange': exchange,449 'address': e_ip[2]})450 for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.AAAA):451 for rdata in rdataset:452 print_status('\t AAAA {0} {1}'.format(str(name) + '.' + self._domain,453 rdata.address))454 zone_records.append({'zone_server': ns_srv, 'type': 'AAAA',455 'name': str(name) + '.' + self._domain,456 'address': rdata.address})457 for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.A):458 for rdata in rdataset:459 print_status('\t A {0} {1}'.format(str(name) + '.' + self._domain,460 rdata.address))461 zone_records.append({'zone_server': ns_srv, 'type': 'A',462 'name': str(name) + '.' + self._domain,463 'address': rdata.address})464 for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.CNAME):465 for rdata in rdataset:466 for t_ip in self.get_ip(rdata.target.to_text()):467 if re.search(r'^A', t_ip[0]):468 if rdata.target.to_text().endswith('.'):469 ctarget = rdata.target.to_text()[:-1]470 else:471 ctarget = rdata.target.to_text()472 print_status('\t CNAME {0} {1} {2}'.format(str(name) + '.' + self._domain,473 rdata.target.to_text(), t_ip[2]))474 zone_records.append({'zone_server': ns_srv, 'type': 'CNAME',475 'name': str(name) + '.' + self._domain,476 'target': str(ctarget),477 'address': t_ip[2]})478 for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.SRV):479 for rdata in rdataset:480 ip_list = self.get_ip(rdata.target.to_text())481 if ip_list:482 for t_ip in self.get_ip(rdata.target.to_text()):483 if re.search(r'^A', t_ip[0]):484 print_status('\t SRV {0} {1} {2} {3} {4}'.format(str(name) + '.' + self._domain, rdata.target,485 str(rdata.port), str(rdata.weight), t_ip[2]))486 zone_records.append({'zone_server': ns_srv, 'type': 'SRV',487 'name': str(name) + '.' + self._domain,488 'target': rdata.target.to_text()[:-1],489 'address': t_ip[2],490 'port': str(rdata.port),491 'weight': str(rdata.weight)})492 else:493 print_status('\t SRV {0} {1} {2} {3} {4}'.format(str(name) + '.' + self._domain, rdata.target,494 str(rdata.port), str(rdata.weight), 'no_ip'))495 zone_records.append({'zone_server': ns_srv, 'type': 'SRV',496 'name': str(name) + '.' + self._domain,497 'target': rdata.target.to_text()[:-1],498 'address': "no_ip",499 'port': str(rdata.port),500 'weight': str(rdata.weight)})501 for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.HINFO):502 for rdata in rdataset:503 print_status('\t HINFO {0} {1}'.format(rdata.cpu.decode(), rdata.os.decode()))504 zone_records.append({'zone_server': ns_srv, 'type': 'HINFO',505 'cpu': rdata.cpu.decode(), 'os': rdata.os.decode()})506 for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.WKS):507 for rdata in rdataset:508 print_status('\t WKS {0} {1} {2}'.format(rdata.address, rdata.bitmap, rdata.protocol))509 zone_records.append({'zone_server': ns_srv, 'type': 'WKS',510 'address': rdata.address, 'bitmap': rdata.bitmap,511 'protocol': rdata.protocol})512 for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.RP):513 for rdata in rdataset:514 print_status('\t RP {0} {1}'.format(rdata.mbox, rdata.txt))515 zone_records.append({'zone_server': ns_srv, 'type': 'RP',516 'mbox': rdata.mbox.to_text(), 'txt': rdata.txt.to_text()})517 for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.AFSDB):518 for rdata in rdataset:519 print_status('\t AFSDB {0} {1}'.format(str(rdata.subtype), rdata.hostname))520 zone_records.append({'zone_server': ns_srv, 'type': 'AFSDB',521 'subtype': str(rdata.subtype), 'hostname': rdata.hostname.to_text()})522 for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.LOC):523 for rdata in rdataset:524 print_status('\t LOC {0}'.format(rdata.to_text()))525 zone_records.append({'zone_server': ns_srv, 'type': 'LOC',526 'coordinates': rdata.to_text()})527 for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.X25):528 for rdata in rdataset:529 print_status('\tX25 {0}'.format(rdata.address))530 zone_records.append({'zone_server': ns_srv, 'type': 'X25',531 'address': rdata.address})532 for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.ISDN):533 for rdata in rdataset:534 print_status('\t ISDN {0}'.format(rdata.address))535 zone_records.append({'zone_server': ns_srv, 'type': 'ISDN',536 'address': rdata.address})537 for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.RT):538 for rdata in rdataset:539 print_status('\t RT {0} {1}'.format(str(rdata.exchange), rdata.preference))540 zone_records.append({'zone_server': ns_srv, 'type': 'X25',541 'address': rdata.address})542 for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.NSAP):543 for rdata in rdataset:544 print_status('\t NSAP {0}'.format(rdata.address))545 zone_records.append({'zone_server': ns_srv, 'type': 'NSAP',546 'address': rdata.address})547 for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.NAPTR):548 for rdata in rdataset:549 print_status('\t NAPTR {0} {1} {2} {3} {4} {5}'.format(rdata.flags.decode(),550 rdata.order,551 rdata.preference,552 rdata.regexp.decode(),553 rdata.replacement.to_text(),554 rdata.service.decode()))555 zone_records.append({'zone_server': ns_srv, 'type': 'NAPTR',556 'order': str(rdata.order),557 'preference': str(rdata.preference),558 'regex': rdata.regexp.decode(),559 'replacement': rdata.replacement.to_text(),560 'service': rdata.service.decode()})561 for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.CERT):562 for rdata in rdataset:563 print_status('\t CERT {0}'.format(rdata.to_text()))564 zone_records.append({'zone_server': ns_srv, 'type': 'CERT',565 'algorithm': rdata.algorithm,566 'certificate': rdata.certificate,567 'certificate_type': rdata.certificate_type,568 'key_tag': rdata.key_tag})569 for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.SIG):570 for rdata in rdataset:571 print_status('\t SIG {0} {1} {2} {3} {4} {5} {6} {7} {8}'.format(572 algorithm_to_text(rdata.algorithm), rdata.expiration,573 rdata.inception, rdata.key_tag, rdata.labels, rdata.original_ttl,574 rdata.signature, str(rdata.signer), rdata.type_covered))575 zone_records.append({'zone_server': ns_srv, 'type': 'SIG',576 'algorithm': algorithm_to_text(rdata.algorithm),577 'expiration': rdata.expiration,578 'inception': rdata.inception,579 'key_tag': rdata.key_tag,580 'labels': rdata.labels,581 'original_ttl': rdata.original_ttl,582 'signature': rdata.signature,583 'signer': str(rdata.signer),584 'type_covered': rdata.type_covered})585 for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.RRSIG):586 for rdata in rdataset:587 print_status('\t RRSIG {0} {1} {2} {3} {4} {5} {6} {7} {8}'.format(588 algorithm_to_text(rdata.algorithm), rdata.expiration,589 rdata.inception, rdata.key_tag, rdata.labels, rdata.original_ttl,590 rdata.signature, str(rdata.signer), rdata.type_covered))591 zone_records.append({'zone_server': ns_srv, 'type': 'RRSIG',592 'algorithm': algorithm_to_text(rdata.algorithm),593 'expiration': rdata.expiration,594 'inception': rdata.inception,595 'key_tag': rdata.key_tag,596 'labels': rdata.labels,597 'original_ttl': rdata.original_ttl,598 'signature': rdata.signature,599 'signer': str(rdata.signer),600 'type_covered': rdata.type_covered})601 for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.DNSKEY):602 for rdata in rdataset:603 print_status('\t DNSKEY {0} {1} {2} {3}'.format(604 algorithm_to_text(rdata.algorithm), rdata.flags, dns.rdata._hexify(rdata.key),605 rdata.protocol))606 zone_records.append({'zone_server': ns_srv, 'type': 'DNSKEY',607 'algorithm': algorithm_to_text(rdata.algorithm),608 'flags': rdata.flags,609 'key': dns.rdata._hexify(rdata.key),610 'protocol': rdata.protocol})611 for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.DS):612 for rdata in rdataset:613 print_status('\t DS {0} {1} {2} {3}'.format(algorithm_to_text(rdata.algorithm), dns.rdata._hexify(rdata.digest),614 rdata.digest_type, rdata.key_tag))615 zone_records.append({'zone_server': ns_srv, 'type': 'DS',616 'algorithm': algorithm_to_text(rdata.algorithm),617 'digest': dns.rdata._hexify(rdata.digest),618 'digest_type': rdata.digest_type,619 'key_tag': rdata.key_tag})620 for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.NSEC):621 for rdata in rdataset:622 print_status('\t NSEC {0}'.format(rdata.next))623 zone_records.append({'zone_server': ns_srv, 'type': 'NSEC',624 'next': rdata.next.to_text()})625 for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.NSEC3):626 for rdata in rdataset:627 print_status('\t NSEC3 {0} {1} {2} {3}'.format(algorithm_to_text(rdata.algorithm), rdata.flags,628 rdata.iterations, rdata.salt))629 zone_records.append({'zone_server': ns_srv, 'type': 'NSEC3',630 'algorithm': algorithm_to_text(rdata.algorithm),631 'flags': rdata.flags,632 'iterations': rdata.iterations,633 'salt': dns.rdata._hexify(rdata.salt)})634 for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.NSEC3PARAM):635 for rdata in rdataset:636 print_status('\t NSEC3PARAM {0} {1} {2} {3}'.format(algorithm_to_text(rdata.algorithm), rdata.flags,637 rdata.iterations, rdata.salt))638 zone_records.append({'zone_server': ns_srv, 'type': 'NSEC3PARAM',639 'algorithm': algorithm_to_text(rdata.algorithm),640 'flags': rdata.flags,641 'iterations': rdata.iterations,642 'salt': dns.rdata._hexify(rdata.salt)})643 for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.IPSECKEY):644 for rdata in rdataset:645 print_status('\t PSECKEY {0} {1} {2} {3} {4}'.format(algorithm_to_text(rdata.algorithm), rdata.gateway,646 rdata.gateway_type, dns.rdata._hexify(rdata.key), rdata.precedence))647 zone_records.append({'zone_server': ns_srv, 'type': 'IPSECKEY',648 'algorithm': algorithm_to_text(rdata.algorithm),649 'gateway': rdata.gateway,650 'gateway_type': rdata.gateway_type,651 'key': dns.rdata._hexify(rdata.key),652 'precedence': rdata.precedence})653 except Exception as e:654 print_error('Zone Transfer Failed!')655 print_error(e)656 import traceback as t657 t.print_exc()658 zone_records.append({'type': 'info', 'zone_transfer': 'failed', 'ns_server': ns_srv})659 else:660 print_error('Zone Transfer Failed for {0}!'.format(ns_srv))661 print_error('Port 53 TCP is being filtered')662 zone_records.append({'type': 'info', 'zone_transfer': 'failed', 'ns_server': ns_srv})...

Full Screen

Full Screen

predict.py

Source:predict.py Github

copy

Full Screen

...56 predicts = outputs[:2]57 predicts = predicts[0]58 max_val = torch.max(predicts)59 label = (predicts == max_val).nonzero().numpy()[0][1]60 ans_label = answer_dic.to_text(label)61 # predict num 2~462 predicts_sort=torch.sort(predicts, descending=True) #將predict值依大小降序排列63 predicts_second=predicts_sort[1][0][1] #predict值第二大的id64 predicts_third=predicts_sort[1][0][2] #predict值第三大的id65 predicts_fourth=predicts_sort[1][0][3] #predict值第三大的id66 67 #predict all (num5~71)-------------------------------------------------68 predicts_fifth=predicts_sort[1][0][4]69 predicts_sixth=predicts_sort[1][0][5]70 predicts_seventh=predicts_sort[1][0][6]71 predicts_eighth=predicts_sort[1][0][7]72 predicts_ninth=predicts_sort[1][0][8]73 predicts_tenth=predicts_sort[1][0][9]74 predicts_eleven=predicts_sort[1][0][10]75 predicts_twelfth=predicts_sort[1][0][11]76 predicts_thirteen=predicts_sort[1][0][12]77 predicts_fourteen=predicts_sort[1][0][13]78 predicts_fifteen=predicts_sort[1][0][14]79 predicts_sixteen=predicts_sort[1][0][15]80 predicts_seventeen=predicts_sort[1][0][16]81 predicts_eighteen=predicts_sort[1][0][17]82 predicts_ninteen=predicts_sort[1][0][18]83 predicts_twenty=predicts_sort[1][0][19]84 predicts_twenty_first=predicts_sort[1][0][20]85 predicts_twenty_second=predicts_sort[1][0][21]86 predicts_twenty_third=predicts_sort[1][0][22]87 predicts_twenty_fourth=predicts_sort[1][0][23]88 predicts_twenty_fifth=predicts_sort[1][0][24]89 predicts_twenty_sixth=predicts_sort[1][0][25]90 predicts_twenty_seventh=predicts_sort[1][0][26]91 predicts_twenty_eighth=predicts_sort[1][0][27]92 predicts_twenty_ninth=predicts_sort[1][0][28]93 predicts_thirty=predicts_sort[1][0][29]94 predicts_thirty_first=predicts_sort[1][0][30]95 predicts_thirty_second=predicts_sort[1][0][31]96 predicts_thirty_third=predicts_sort[1][0][32]97 predicts_thirty_fourth=predicts_sort[1][0][33]98 predicts_thirty_fifth=predicts_sort[1][0][34]99 predicts_thirty_sixth=predicts_sort[1][0][35]100 predicts_thirty_seventh=predicts_sort[1][0][36]101 predicts_thirty_eighth=predicts_sort[1][0][37]102 predicts_thirty_ninth=predicts_sort[1][0][38]103 predicts_forty=predicts_sort[1][0][39]104 predicts_forty_first=predicts_sort[1][0][40]105 predicts_forty_second=predicts_sort[1][0][41]106 predicts_forty_third=predicts_sort[1][0][42]107 predicts_forty_fourth=predicts_sort[1][0][43]108 predicts_forty_fifth=predicts_sort[1][0][44]109 predicts_forty_sixth=predicts_sort[1][0][45]110 predicts_forty_seventh=predicts_sort[1][0][46]111 predicts_forty_eighth=predicts_sort[1][0][47]112 predicts_forty_ninth=predicts_sort[1][0][48]113 predicts_fifty=predicts_sort[1][0][49]114 predicts_fifty_first=predicts_sort[1][0][50]115 predicts_fifty_second=predicts_sort[1][0][51]116 predicts_fifty_third=predicts_sort[1][0][52]117 predicts_fifty_fourth=predicts_sort[1][0][53]118 predicts_fifty_fifth=predicts_sort[1][0][54]119 predicts_fifty_sixth=predicts_sort[1][0][55]120 predicts_fifty_seventh=predicts_sort[1][0][56]121 predicts_fifty_eighth=predicts_sort[1][0][57]122 predicts_fifty_ninth=predicts_sort[1][0][58]123 predicts_sixty=predicts_sort[1][0][59]124 predicts_sixty_first=predicts_sort[1][0][60]125 predicts_sixty_second=predicts_sort[1][0][61]126 predicts_sixty_third=predicts_sort[1][0][62]127 predicts_sixty_fourth=predicts_sort[1][0][63]128 predicts_sixty_fifth=predicts_sort[1][0][64]129 predicts_sixty_sixth=predicts_sort[1][0][65]130 predicts_sixty_seventh=predicts_sort[1][0][66]131 predicts_sixty_eighth=predicts_sort[1][0][67]132 predicts_sixty_ninth=predicts_sort[1][0][68]133 predicts_seventy=predicts_sort[1][0][69]134 predicts_seventy_first=predicts_sort[1][0][70]135 #---------------------------------------------------------------------136 137 138 139 #把2~4的predict id回去查表140 ans_labelsecond=answer_dic.to_text(predicts_second) #predict第二順位答案141 ans_labelthird=answer_dic.to_text(predicts_third) #predict第三順位答案142 ans_labelfourth=answer_dic.to_text(predicts_fourth) #predict第四順位答案143 144 #查表: num5~71---------------------------------------------------------145 ans_label_5=answer_dic.to_text(predicts_fifth)146 ans_label_6=answer_dic.to_text(predicts_sixth) 147 ans_label_7=answer_dic.to_text(predicts_seventh)148 ans_label_8=answer_dic.to_text(predicts_eighth)149 ans_label_9=answer_dic.to_text(predicts_ninth) 150 ans_label_10=answer_dic.to_text(predicts_tenth)151 ans_label_11=answer_dic.to_text(predicts_eleven)152 ans_label_12=answer_dic.to_text(predicts_twelfth) 153 ans_label_13=answer_dic.to_text(predicts_thirteen)154 ans_label_14=answer_dic.to_text(predicts_fourteen)155 ans_label_15=answer_dic.to_text(predicts_fifteen) 156 ans_label_16=answer_dic.to_text(predicts_sixteen)157 ans_label_17=answer_dic.to_text(predicts_seventeen)158 ans_label_18=answer_dic.to_text(predicts_eighteen) 159 ans_label_19=answer_dic.to_text(predicts_ninteen)160 ans_label_20=answer_dic.to_text(predicts_twenty)161 ans_label_21=answer_dic.to_text(predicts_twenty_first) 162 ans_label_22=answer_dic.to_text(predicts_twenty_second)163 ans_label_23=answer_dic.to_text(predicts_twenty_third)164 ans_label_24=answer_dic.to_text(predicts_twenty_fourth) 165 ans_label_25=answer_dic.to_text(predicts_twenty_fifth)166 ans_label_26=answer_dic.to_text(predicts_twenty_sixth)167 ans_label_27=answer_dic.to_text(predicts_twenty_seventh) 168 ans_label_28=answer_dic.to_text(predicts_twenty_eighth)169 ans_label_29=answer_dic.to_text(predicts_twenty_ninth)170 ans_label_30=answer_dic.to_text(predicts_thirty)171 ans_label_31=answer_dic.to_text(predicts_thirty_first) 172 ans_label_32=answer_dic.to_text(predicts_thirty_second)173 ans_label_33=answer_dic.to_text(predicts_thirty_third)174 ans_label_34=answer_dic.to_text(predicts_thirty_fourth) 175 ans_label_35=answer_dic.to_text(predicts_thirty_fifth)176 ans_label_36=answer_dic.to_text(predicts_thirty_sixth)177 ans_label_37=answer_dic.to_text(predicts_thirty_seventh) 178 ans_label_38=answer_dic.to_text(predicts_thirty_eighth)179 ans_label_39=answer_dic.to_text(predicts_thirty_ninth)180 ans_label_40=answer_dic.to_text(predicts_forty)181 ans_label_41=answer_dic.to_text(predicts_forty_first) 182 ans_label_42=answer_dic.to_text(predicts_forty_second)183 ans_label_43=answer_dic.to_text(predicts_forty_third)184 ans_label_44=answer_dic.to_text(predicts_forty_fourth) 185 ans_label_45=answer_dic.to_text(predicts_forty_fifth)186 ans_label_46=answer_dic.to_text(predicts_forty_sixth)187 ans_label_47=answer_dic.to_text(predicts_forty_seventh) 188 ans_label_48=answer_dic.to_text(predicts_forty_eighth)189 ans_label_49=answer_dic.to_text(predicts_forty_ninth)190 ans_label_50=answer_dic.to_text(predicts_fifty)191 ans_label_51=answer_dic.to_text(predicts_fifty_first) 192 ans_label_52=answer_dic.to_text(predicts_fifty_second)193 ans_label_53=answer_dic.to_text(predicts_fifty_third)194 ans_label_54=answer_dic.to_text(predicts_fifty_fourth) 195 ans_label_55=answer_dic.to_text(predicts_fifty_fifth)196 ans_label_56=answer_dic.to_text(predicts_fifty_sixth)197 ans_label_57=answer_dic.to_text(predicts_fifty_seventh) 198 ans_label_58=answer_dic.to_text(predicts_fifty_eighth)199 ans_label_59=answer_dic.to_text(predicts_fifty_ninth)200 ans_label_60=answer_dic.to_text(predicts_sixty)201 ans_label_61=answer_dic.to_text(predicts_sixty_first) 202 ans_label_62=answer_dic.to_text(predicts_sixty_second)203 ans_label_63=answer_dic.to_text(predicts_sixty_third)204 ans_label_64=answer_dic.to_text(predicts_sixty_fourth) 205 ans_label_65=answer_dic.to_text(predicts_sixty_fifth)206 ans_label_66=answer_dic.to_text(predicts_sixty_sixth)207 ans_label_67=answer_dic.to_text(predicts_sixty_seventh) 208 ans_label_68=answer_dic.to_text(predicts_sixty_eighth)209 ans_label_69=answer_dic.to_text(predicts_sixty_ninth)210 ans_label_70=answer_dic.to_text(predicts_seventy)211 ans_label_71=answer_dic.to_text(predicts_seventy_first)212 #---------------------------------------------------------------------213 214 215 216 print("醫護人員問的話: ",q_input)217 print('病人想要的回答(最佳解答): ',ans_label)218 print("病人想要的回答(第2~4順位): ",ans_labelsecond,ans_labelthird,ans_labelfourth)219 220 # print num 5~71-------------------------------------------------------221 print("病人想要的回答(第5~10順位): ",ans_label_5,ans_label_6,ans_label_7,ans_label_8,ans_label_9,ans_label_10)222 print("病人想要的回答(第11~20順位): ",ans_label_11,ans_label_12,ans_label_13,ans_label_14,ans_label_15,ans_label_16,ans_label_17,ans_label_18,ans_label_19,ans_label_20)223 print("病人想要的回答(第21~30順位): ",ans_label_21,ans_label_22,ans_label_23,ans_label_24,ans_label_25,ans_label_26,ans_label_27,ans_label_28,ans_label_29,ans_label_30)224 print("病人想要的回答(第31~40順位): ",ans_label_31,ans_label_32,ans_label_33,ans_label_34,ans_label_35,ans_label_36,ans_label_37,ans_label_38,ans_label_39,ans_label_40)225 print("病人想要的回答(第41~50順位): ",ans_label_41,ans_label_42,ans_label_43,ans_label_44,ans_label_45,ans_label_46,ans_label_47,ans_label_48,ans_label_49,ans_label_50)...

Full Screen

Full Screen

main.py

Source:main.py Github

copy

Full Screen

...9 for rrsets in answer:10 if type(rrsets) == dns.message.QueryMessage:11 for rr in rrsets.answer:12 for rdata in rr:13 if dns.rdatatype.to_text(rdata.rdtype) not in toreturn:14 toreturn[dns.rdatatype.to_text(rdata.rdtype)] = []15 toreturn[dns.rdatatype.to_text(rdata.rdtype)].append(rdata.to_text())16 return jsonify(toreturn)17@app.route('/api/dns/<domain>/<qtype>')18def resolvetype(domain, qtype):19 toreturn = {}20 request = dns.message.make_query(domain, qtype, "IN", use_edns=False, want_dnssec=True)21 answer = dns.query.udp_with_fallback(request, "8.8.8.8", timeout=2)22 for rrsets in answer:23 if type(rrsets) == dns.message.QueryMessage:24 for rr in rrsets.answer:25 for rdata in rr:26 if dns.rdatatype.to_text(rdata.rdtype) not in toreturn:27 toreturn[dns.rdatatype.to_text(rdata.rdtype)] = []28 toreturn[dns.rdatatype.to_text(rdata.rdtype)].append(rdata.to_text())29 return jsonify(toreturn)30@app.route('/api/dns/<domain>/<qtype>/<nameserver>')31def resolvetypens(domain, qtype, nameserver):32 toreturn = {}33 request = dns.message.make_query(domain, qtype, "IN", use_edns=False, want_dnssec=True)34 answer = dns.query.udp_with_fallback(request, nameserver, timeout=2)35 for rrsets in answer:36 if type(rrsets) == dns.message.QueryMessage:37 for rr in rrsets.answer:38 for rdata in rr:39 if dns.rdatatype.to_text(rdata.rdtype) not in toreturn:40 toreturn[dns.rdatatype.to_text(rdata.rdtype)] = []41 toreturn[dns.rdatatype.to_text(rdata.rdtype)].append(rdata.to_text())42 return jsonify(toreturn)43@app.route('/api/dns/<domain>/<qtype>/<nameserver>/tls')44def resolvetls(domain, qtype, nameserver):45 toreturn = {}46 request = dns.message.make_query(domain, qtype, "IN", use_edns=False, want_dnssec=True)47 rrsets = dns.query.tls(request, nameserver, timeout=2)48 if type(rrsets) == dns.message.QueryMessage:49 for rr in rrsets.answer:50 for rdata in rr:51 if dns.rdatatype.to_text(rdata.rdtype) not in toreturn:52 toreturn[dns.rdatatype.to_text(rdata.rdtype)] = []53 toreturn[dns.rdatatype.to_text(rdata.rdtype)].append(rdata.to_text())54 return jsonify(toreturn)55@app.route('/api/dns/<domain>/<qtype>/<nameserver>/https')56def resolvehttps(domain, qtype, nameserver):57 toreturn = {}58 request = dns.message.make_query(domain, qtype, "IN", use_edns=False, want_dnssec=True)59 rrsets = dns.query.https(request, nameserver, timeout=2)60 if type(rrsets) == dns.message.QueryMessage:61 for rr in rrsets.answer:62 for rdata in rr:63 if dns.rdatatype.to_text(rdata.rdtype) not in toreturn:64 toreturn[dns.rdatatype.to_text(rdata.rdtype)] = []65 toreturn[dns.rdatatype.to_text(rdata.rdtype)].append(rdata.to_text())...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run avocado automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful