by Saurabh Gupta (4 Submissions)
Category: Internet/HTML
Compatability: Visual Basic 3.0
Difficulty: Intermediate
Date Added: Wed 3rd February 2021
Rating:
(15 Votes)

This code looks up MX (Mail eXchange) records for any domain from a DNS server (For those who dont know what a MX record is, MX records contain the name of the SMTP server which receives mail for a domain).
This is an improvement (I hope so :) over Jason Martin's code (https://www.vbcoders.com/vb/scripts/ShowCode.asp?txtCodeId=11006&lngWId=1). Here are the changes I made:
1. It uses winsock and not API for the query.
2. It wont freeze if you give a non-existent domain or DNS server.
3. It gets the DNS server in use by your computer by network api instead of registry.
4. There was a bug in Jason's code due to which if the DNS response was compressed it would return only the first MX record. For example, Jason's code would return one MX record for earthlink.com while mine will return all five.
I'll appreciate any feedback on this code.
Code Returns
The MX records of a domain.
API DeclarationsA few in the code.
Download MX Query (26 KB)