in reply to Creating a web application in Perl
Pinging a domain name is not an especially good indicator - there are a number of scenarios where a domain name will not respond to pings, but can accept mail.
example.org. MX 10 mail.example.org. mail.example.org. A 10.10.10.1. www.example.org. A 10.10.10.2.You will end up with a situation where mail.example.org and www.example.org will accept pings, but example.org will not accept pings (unknown host), yet addresses like joe@example.org can still be received.
So don't ping the domain. Use a Perl module like Net::DNS::Resolver to look up an MX record for the host; if there is no MX record, then look for an A/AAAA/CNAME record; if you've still not found a matching DNS entry, then the domain name probably can't receive mail.
use Net::DNS::Resolver; my $domain = 'example.com'; my $dns = Net::DNS::Resolver->new; my $valid = $dns->query($domain, 'MX') || gethostbyname($domain); printf( "You could %s send mail to %s.\n", ($valid ? "maybe" : "not"), $domain, );
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Creating a web application in Perl
by cavac (Prior) on Jan 07, 2012 at 13:37 UTC |