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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:41:12+00:00 2026-05-11T22:41:12+00:00

I am writing an application that is requiring me to do a DNS lookup

  • 0

I am writing an application that is requiring me to do a DNS lookup for an MX record. I’m not sure if anyone has had experience doing this kind of work but if you do, any help would be appreciated.

EDIT:
The thing that I’m going for is an application that will send an e-mail alert. The problem is I need to have the application be able to lookup the MX record for a domain.

  • 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-11T22:41:12+00:00Added an answer on May 11, 2026 at 10:41 pm

    The simplest method is to simply use commonly available tools.

    The basic “dig” command will return the records to you via this query:

    dig mx example.com
    

    If you want just the lines with the mx records…

    dig mx example.com | grep -v '^;' | grep example.com
    

    dig is available on most linux / unix boxes.

    If you’re on windows you can use nslookup

    nslookup -type=mx example.com
    

    Then just parse the output of these common tools.

    EDIT: Simple C example of sockets from the web

    Since you put “C” as a tag, I guess you’re looking for source code to do MX lookups using raw sockets. I copied this from http://www.developerweb.net/forum/showthread.php?t=3550. It may be more what you’re looking for?

    #include <stdio.h>
    #include <stdlib.h>
    #include <unistd.h>
    #include <netinet/in.h>
    #include <resolv.h>
    
    int main (int argc, char *argv[])
    {
        u_char nsbuf[4096];
        char dispbuf[4096];
        ns_msg msg;
        ns_rr rr;
        int i, j, l;
    
        if (argc < 2) {
            printf ("Usage: %s <domain>[...]\n", argv[0]);
            exit (1);
        }
    
        for (i = 1; i < argc; i++) {
            l = res_query (argv[i], ns_c_any, ns_t_mx, nsbuf, sizeof (nsbuf));
            if (l < 0) {
                perror (argv[i]);
            } else {
    #ifdef USE_PQUERY
    /* this will give lots of detailed info on the request and reply */
                res_pquery (&_res, nsbuf, l, stdout);
    #else
    /* just grab the MX answer info */
                ns_initparse (nsbuf, l, &msg);
                printf ("%s :\n", argv[i]);
                l = ns_msg_count (msg, ns_s_an);
                for (j = 0; j < l; j++) {
                    ns_parserr (&msg, ns_s_an, j, &rr);
                    ns_sprintrr (&msg, &rr, NULL, NULL, dispbuf, sizeof (dispbuf));
                    printf ("%s\n", dispbuf);
                }
    #endif
            }
        }
    
        exit (0);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing an application that has a timer functionality built in. Unfortunately, I'm having
im writing an application that downloads and installs addons for programs which needs to
I am writing an application that downloads large files in the background. All clients
I'm writing an application that on some stage performs low-level disk operations in Linux
I am writing an application that needs to bring window of an external app
I'm writing an application that is basically just a preferences dialog, much like the
I am writing an application that if the user hits back, it may resend
I am current writing an application that will require multiple inserts, updates and deletes
Say you are writing an application that must implement the HTTP protocol. Protocols are
I'm writing an application that uses renaming rules to rename a list of files

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.