Python Forum
Simple list question - I think?
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Simple list question - I think?
#1
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

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)
Reply
#2
As a follow up. I changed my print to a pprint and it shows all the information.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Simple Question - ' defined as "a". ?' Ryan012 10 1,490 May-27-2023, 06:03 PM
Last Post: Ryan012
  Very simple question about filenames and backslashes! garynewport 4 1,830 Jan-17-2023, 05:02 AM
Last Post: deanhystad
  Python Tkinter Simple Multithreading Question AaronCatolico1 5 1,468 Dec-14-2022, 11:35 PM
Last Post: deanhystad
  A simple "If...Else" question from a beginner Serena2022 6 1,638 Jul-11-2022, 05:59 AM
Last Post: Serena2022
  Simple arithmetic question ebolisa 5 2,007 Dec-15-2021, 04:56 PM
Last Post: deanhystad
  Simple code question about lambda and tuples JasPyt 7 3,238 Oct-04-2021, 05:18 PM
Last Post: snippsat
Big Grin question about simple algorithm to my problem jamie_01 1 1,634 Oct-04-2021, 11:55 AM
Last Post: deanhystad
  Simple question 1234 4 2,227 Dec-04-2020, 12:29 PM
Last Post: DeaD_EyE
  Simple Timer Question cranberrica 3 2,139 Jun-22-2020, 06:29 PM
Last Post: cranberrica
  Simple question on tab stuartsmith22 4 2,382 Apr-15-2020, 04:42 PM
Last Post: stuartsmith22

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020