Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3596650
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:00:58+00:00 2026-05-18T20:00:58+00:00

I consider myself a very beginner at python(and programming in general!), but I am

  • 0

I consider myself a very beginner at python(and programming in general!), but I am working though “learn python the hard way” by Zed A Shaw and slowing picking things up.
I’m writing a little script to check if the live mx records of a domain are to be as expected and have not been changed (long story) and so far I have the following:

import dns.resolver
domain = 'bbc.co.uk'
for x in dns.resolver.query(domain,'MX',):
    print x.to_text()

This uses the dnspython module to spit out the mailhost and the preference number. What I need to do now is compare this output to the two expected results, so for bbc.co.uk those would be cluster1a.eu.messagelabs.com. & cluster1.eu.messagelabs.com. (Their ordering changes depending on the current preference number)

I thought the best way to do this would to be to add the expected results to a array/list and have the script try and compare the output to the array/list and provide a true or false statement, but after spending all day trying different arrangements of code this is proving to be beyond my understanding so far.

Eventually I would like it to alert myself or my colleagues if the result come up false, but that can wait until later as I haven’t decided on the best method for this to be implemented.
Would any kind soul be able to give me a rough outline of what the best practice would be to achieve the result I am hoping for?

I appreciate anyone taking the time to read this 🙂

Thank you, Chris

EDIT:This appears to do exactly what I was hoping for, thank you everyone for you help!

import dns.resolver
domain = 'bbc.co.uk'
expected_responses = ['cluster1.eu.messagelabs.com.', 'cluster1a.eu.messagelabs.com.']
for x in dns.resolver.query(domain, 'MX'):
        if x.to_text().split()[1] not in expected_responses:
                print "Unexpected MX record found!"
        else:
                print x.to_text().split()[1] + " OK!"
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T20:00:59+00:00Added an answer on May 18, 2026 at 8:00 pm

    The results are returned in the format ‘XX dns_entry’, so you can do:

    import dns.resolver
    domain = 'bbc.co.uk'
    results = []
    for x in dns.resolver.query(domain,'MX',):
        results.append(x.to_text().split(' ')[1])
    print results
    
    >>> ['cluster1.eu.messagelabs.com.', 'cluster1a.eu.messagelabs.com.']
    

    Now you can compare against this list.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I consider myself quite fluent in PHP and am rather familiar with nearly all
Consider the following setup: A windows PC with a LAN interface and a WiFi
Consider the need to develop a lightweight desktop DB application on the Microsoft platforms.
Consider: List<String> someList = new ArrayList<>(); // add "monkey", "donkey", "skeleton key" to someList
Consider this problem: I have a program which should fetch (let's say) 100 records
Consider these two function definitions: void foo() { } void foo(void) { } Is
Consider the Oracle emp table. I'd like to get the employees with the top
Consider an indexed MySQL table with 7 columns, being constantly queried and written to.
Consider these classes. class Base { ... }; class Derived : public Base {
Consider the following ruby code test.rb: begin puts thisFunctionDoesNotExist x = 1+1 rescue Exception

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.