Jun-06-2018, 06:58 PM
Hello,
This may be a simple question regarding lists. I am using dnspython to perform a dns.resolver to get all the records for a domain. It creates a list with an append and if I print that list, it gives me output like this [<DNS IN A rdata: 172.217.6.206>, <DNS IN AAAA rdata: 2607:f8b0:4006:812::200e>, Ultimately I am looking to strip and format this output to say "A 172.217.6.206" on one line and "AAAA 2607:f8b0:4006:812::200e" on another.
I thought I could iterate through the list and print each line. When I do with the following code, it prints the answer and not the type of record like this. There is no <> symbols or information what type of record is on each line. What am I doing wrong?
172.217.10.110
2607:f8b0:4006:805::200e
50 alt4.aspmx.l.google.com.
20 alt1.aspmx.l.google.com.
10 aspmx.l.google.com.
30 alt2.aspmx.l.google.com.
40 alt3.aspmx.l.google.com.
"v=spf1 include:_spf.google.com ~all"
"facebook-domain-verification=22rm551cu4k0ab0bxsw536tlds4h95"
"docusign=05958488-4752-4ef2-95eb-aa7ba8a3bd0e"
ns1.google.com. dns-admin.google.com. 199450551 900 900 1800 60
ns1.google.com.
ns4.google.com.
ns3.google.com.
ns2.google.com.
Here is my code. Currently it prints both of the examples
This may be a simple question regarding lists. I am using dnspython to perform a dns.resolver to get all the records for a domain. It creates a list with an append and if I print that list, it gives me output like this [<DNS IN A rdata: 172.217.6.206>, <DNS IN AAAA rdata: 2607:f8b0:4006:812::200e>, Ultimately I am looking to strip and format this output to say "A 172.217.6.206" on one line and "AAAA 2607:f8b0:4006:812::200e" on another.
I thought I could iterate through the list and print each line. When I do with the following code, it prints the answer and not the type of record like this. There is no <> symbols or information what type of record is on each line. What am I doing wrong?
172.217.10.110
2607:f8b0:4006:805::200e
50 alt4.aspmx.l.google.com.
20 alt1.aspmx.l.google.com.
10 aspmx.l.google.com.
30 alt2.aspmx.l.google.com.
40 alt3.aspmx.l.google.com.
"v=spf1 include:_spf.google.com ~all"
"facebook-domain-verification=22rm551cu4k0ab0bxsw536tlds4h95"
"docusign=05958488-4752-4ef2-95eb-aa7ba8a3bd0e"
ns1.google.com. dns-admin.google.com. 199450551 900 900 1800 60
ns1.google.com.
ns4.google.com.
ns3.google.com.
ns2.google.com.
Here is my code. Currently it prints both of the examples
import dns.resolver def dnstest(domain): dnsrecords = [] record_types = ['A', 'AAAA', 'CNAME', 'MX', 'SRV', 'TXT', 'SOA', 'NS'] dnsResolver = dns.resolver.Resolver() dnsResolver.timeout = 1 dnsResolver.lifetime = 1 for record in record_types: try: dnsAnswer = dnsResolver.query(domain, record) for rdata in dnsAnswer: dnsrecords.append(rdata) except: pass return(dnsrecords) mylist=(dnstest("acsgj.com")) # Print the list - creates the odd data print(mylist) # print each element - doesn't show the odd data or the type of record for i in mylist: print(i)