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 839933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T05:32:34+00:00 2026-05-15T05:32:34+00:00

I am setting up a dns lookup form using dns_get_record. I set it up

  • 0

I am setting up a dns lookup form using dns_get_record. I set it up to check the A Record and MX Records of the domain that is input. However, I would like it to also display the IP address of the displayed MX Records. Is this possible?

  • 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-15T05:32:35+00:00Added an answer on May 15, 2026 at 5:32 am

    No, at least not in one step. You’ll have to do another dns request for the “target” of the MX record, which is the “real” address of the mail server.

    A simple script could look like this

    $email = "anyone@staff.example.com";
    list( $tmp, $email ) = explode( "@", $email );  // Gets the domain name
    
    $dns = dns_get_record( $email, DNS_MX );
    if( count($dns) <= 0 )
        die( "Error looking up dns information." ); // Return value is an empty array if there aren't any MX records but domain exists
    
    // Looks up the first returned MX (note that there can be more than one)
    // Each MX record has a 'pri' value where the lowest value is the record with the highest priority
    $mx = dns_get_record( $dns[0]['target'], DNS_A );
    if( count($mx) <= 0 )
        die( "Error looking up mail server." );
    $mx = $mx[0]['ip'];
    

    A full blown A and MX record displaying script

    $domain = "google.com";
    
    $dns = dns_get_record( $domain, DNS_ANY );
    foreach( $dns as $d ) {
        // Only print A and MX records
        if( $d['type'] != "A" and $d['type'] != "MX" )
            continue;
        // First print all fields
        echo "--- " . $d['host'] . ": <br />\n";
        foreach( $d as $key => $value ) {
            if( $key != "host" )    // Don't print host twice
                echo " {$key}: {$value} <br />\n";
        }
        // Print type specific fields
        switch( $d['type'] ) {
            case 'A':
                // Display annoying message
                echo "A records always contain an IP address. <br />\n";
                break;
            case 'MX':
                // Resolve IP address of the mail server
                $mx = dns_get_record( $d['target'], DNS_A );
                foreach( $mx as $server ) {
                    echo "The MX record for " . $d['host'] . " points to the server " . $d['target'] . " whose IP address is " . $server['ip'] . ". <br />\n";
                }
                break;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a beginner in programming. I wrote a script to set DNS setting using
I'm playing with DNS record lookup in PHP and am running into something confusing.
The java.net.InetAddress.GetByName(String host) method can only return A records so to lookup other record
I'd like to create a script that will toggle between setting the DNS settings
Setting onchange event for CheckBoxList using the following code doesn't work. chkListUserGroup.Attributes.Add(onchange, document.forms[0].isRecordModified.value='true';); How
I have a domain, call it mydom.com. A while ago I started using Google
After setting up Apache virtual hosts with hostnames server1 and server2, how would I
I'm setting up a registration page, and I'm using PHP primarily to verify the
I'm using CloudFlare CDN on my Rails 3.1 application. Cloudflare is a CDN that
I have some wrapper code that runs a set of NUnit tests that scan

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.