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, );
In reply to Re: Creating a web application in Perl
by tobyink
in thread Creating a web application in Perl
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |