I am using gethostbyname() to check if the domain part of an email address has a valid DNS. Why is it that for some addresses like say <foo@bar.com> 'bar.com' has a DNS entry but for other addresses such as <foo@baz.com> 'baz.com' does not have a DNS entry but 'www.baz.com' does. In real life both these email addresses are valid and deliverable, its just that when you check the domain part with gethostbyname() you need to append the 'www.' prefix. I have settled on this:
for (keys %emails) { my ($domain) = $_ =~ m/<[^@]+@([^>]+)>/; my $dns = gethostbyname($domain) || gethostbyname("www.$domain"); $dns = $dns ? "OK DNS" : "No DNS"; print "$dns email: $_ page(s): $emails{$_}\n"; }
Can someone please explain this seemingly random requirement for 'www.' to me?
Thanks
In reply to gethostbyname() and www prefix by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |