DR695H | c9392aa | 2019-05-24 16:23:44 -0400 | [diff] [blame] | 1 | import dns.message |
| 2 | import dns.name |
| 3 | import dns.query |
| 4 | from robot.api.deco import keyword |
| 5 | |
| 6 | |
| 7 | class DNSKeywords(object): |
| 8 | """ Utilities useful for DNS requests """ |
| 9 | |
| 10 | def __init__(self): |
| 11 | super(DNSKeywords, self).__init__() |
| 12 | |
| 13 | @keyword |
| 14 | def dns_request(self, domain, ns): |
| 15 | """ return the ip address of the given domain name from the given nameserver """ |
| 16 | request = dns.message.make_query(domain, dns.rdatatype.A) |
| 17 | request.flags |= dns.flags.AD |
| 18 | request.find_rrset(request.additional, dns.name.root, 65535, dns.rdatatype.OPT, create=True, force_unique=True) |
| 19 | response = dns.query.udp(request, ns) |
| 20 | |
| 21 | for answer in response.answer: |
| 22 | for item in answer.items: |
| 23 | return item |