DR695H | 5fa0146 | 2017-02-15 18:21:12 -0500 | [diff] [blame] | 1 | import dns.message |
| 2 | import dns.name |
| 3 | import dns.query |
| 4 | |
| 5 | class DNSUtils: |
| 6 | """ Utilities useful for DNS requests """ |
| 7 | |
| 8 | def dns_request(self, domain, ns): |
| 9 | """ return the ip address of the given domain name from the given nameserver """ |
| 10 | request = dns.message.make_query(domain, dns.rdatatype.A); |
| 11 | request.flags |= dns.flags.AD; |
| 12 | request.find_rrset(request.additional, dns.name.root, 65535, dns.rdatatype.OPT, create=True, force_unique=True) |
| 13 | response = dns.query.udp(request, ns) |
| 14 | |
| 15 | for answer in response.answer: |
| 16 | for item in answer.items: |
| 17 | return item |