Gerard has asked for the wisdom of the Perl Monks concerning the following question:
Any ideas?use Net::DNS::Resolver; use Net::DNS::RR; use Net::DNS::Packet; use strict; #Takes an email address and returns the #mx record (uri of the smtp server that looks after this domain) as a +string sub mxLookup(){ #extract the domain from the email address my ($email) = @_; my @parts = split(/\@/, $email); my $domain = @parts[1]; #Create a DNS Resolver and request records of type MX my $server; my $res = new Net::DNS::Resolver; $res->nameservers("202.27.184.3", "202.27.184.5", "203.96.152.4", " +203.96.152.12"); my $packet = $res->send($domain, "MX") || return "error"; #Parse the results to get the preferred smtp server for this domain my $answer = $packet->string; my $answerSection = ";; ANSWER SECTION"; my @results; @results=split(/$answerSection/, $answer); @results=split(/;;/, $results[1]); @results=split(/\)\n/, $results[0]); @results=split(/\n/, $results[1]); my $priority = "99999999999"; foreach(@results){ my @results2=split(/\t/, $_); my @results3=split(/ /, $results2[4]); if ($results3[0] < $priority){ $server = $results3[1]; } } if (!$server){ return "error"; } return $server; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: MX Record Lookups
by rob_au (Abbot) on Dec 10, 2003 at 22:06 UTC | |
by Gerard (Pilgrim) on Dec 10, 2003 at 22:14 UTC | |
|
Re: MX Record Lookups
by Zaxo (Archbishop) on Dec 10, 2003 at 22:29 UTC | |
|
Re: MX Record Lookups
by grinder (Bishop) on Dec 11, 2003 at 11:07 UTC | |
|
Re: MX Record Lookups
by sunadmn (Curate) on Dec 11, 2003 at 14:30 UTC |