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.
The simplest method is to simply use commonly available tools.
The basic “dig” command will return the records to you via this query:
If you want just the lines with the mx records…
dig is available on most linux / unix boxes.
If you’re on windows you can use nslookup
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?