<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Perl script to find the MX records for a given domain in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/perl-script-to-find-the-mx-records-for-a-given-domain/m-p/3955665#M95810</link>
    <description>&lt;!--!*#--&gt;I'm not sure what you want to achieve.&lt;BR /&gt;But if it's the output of the nslookup command that you wish to capture, system() is most likely to be the wrong call,&lt;BR /&gt;unless you run it as a forked child to whom you set up a pipe to either stdin or stdout in advance (bidirectional communication would yet be another story).&lt;BR /&gt;But in this case one would fork and exec anyway, I would say.&lt;BR /&gt;The most simple way to capture a subprocess's output is by using the backticks or the qx delimiter.&lt;BR /&gt;e.g.&lt;BR /&gt;&lt;BR /&gt;my $nslookup_said = qw(/usr/bin/nslookup -q=mx google.com.);&lt;BR /&gt;&lt;BR /&gt;But beware, that this way you cannot avoid that Perl passes the qx() or backticked expression to the shell for expanding any meta characters.&lt;BR /&gt;This is inherently insecure, especially if the expression contains any user input.&lt;BR /&gt;&lt;BR /&gt;A better way would be to use a forked open and execute system() or exec() in the child's copy of the code.&lt;BR /&gt;This way you can pass any command and options or arguments as a list, thereby totally avoiding any shell execution.&lt;BR /&gt;&lt;BR /&gt;e.g.&lt;BR /&gt;&lt;BR /&gt;local *PH;&lt;BR /&gt;my $pid = open(PH, '-|');&lt;BR /&gt;die "Cannot open pipe to nslookup: $!\n" unless defined $pid;&lt;BR /&gt;my $nslookup_said;&lt;BR /&gt;if ($pid) {&lt;BR /&gt;   # let the parent read output from the child&lt;BR /&gt;   # assume moderate amount of output, and slurp&lt;BR /&gt;   local $/;&lt;BR /&gt;   $nslookup_said = &lt;PH&gt;;&lt;BR /&gt;   # parent will block until we close the pipe&lt;BR /&gt;   # note Perl will automatically fetch child's exit code&lt;BR /&gt;   # and place it in $?&lt;BR /&gt;   # releiving us from installing SIGCHLD handler&lt;BR /&gt;   close PH;&lt;BR /&gt;} else {&lt;BR /&gt;   exec qw(/usr/bin/nslookup -q=mx google.com.);&lt;BR /&gt;   # die is the only statement&lt;BR /&gt;   # that may follow an exec&lt;BR /&gt;   die "Cannot fork nslookup: $!\n";&lt;BR /&gt;}&lt;/PH&gt;</description>
    <pubDate>Tue, 24 Apr 2007 11:27:20 GMT</pubDate>
    <dc:creator>Ralph Grothe</dc:creator>
    <dc:date>2007-04-24T11:27:20Z</dc:date>
    <item>
      <title>Perl script to find the MX records for a given domain</title>
      <link>https://community.hpe.com/t5/operating-system-linux/perl-script-to-find-the-mx-records-for-a-given-domain/m-p/3955660#M95805</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I need to find the MX record for a given domain,say&lt;BR /&gt;&lt;BR /&gt;H:\&amp;gt;nslookup -type=mx google.com&lt;BR /&gt;&lt;BR /&gt;Non-authoritative answer:&lt;BR /&gt;google.com      MX preference = 10, mail exchanger = smtp3.google.com&lt;BR /&gt;google.com      MX preference = 10, mail exchanger = smtp4.google.com&lt;BR /&gt;google.com      MX preference = 10, mail exchanger = smtp1.google.com&lt;BR /&gt;google.com      MX preference = 10, mail exchanger = smtp2.google.com&lt;BR /&gt;&lt;BR /&gt;smtp3.google.com        internet address = 64.233.183.25&lt;BR /&gt;smtp4.google.com        internet address = 72.14.215.25&lt;BR /&gt;smtp1.google.com        internet address = 216.239.57.25&lt;BR /&gt;smtp2.google.com        internet address = 64.233.167.25&lt;BR /&gt;&lt;BR /&gt;Instead using Net::DNS module to find,is there anyother way to implement in Perl script.&lt;BR /&gt;I would also like to know about the same in Shell script.&lt;BR /&gt;&lt;BR /&gt;Could you please help me in this&lt;BR /&gt;&lt;BR /&gt;Thanks in advance,&lt;BR /&gt;Arun</description>
      <pubDate>Mon, 05 Mar 2007 09:35:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/perl-script-to-find-the-mx-records-for-a-given-domain/m-p/3955660#M95805</guid>
      <dc:creator>Arun Kumar Rajamari</dc:creator>
      <dc:date>2007-03-05T09:35:32Z</dc:date>
    </item>
    <item>
      <title>Re: Perl script to find the MX records for a given domain</title>
      <link>https://community.hpe.com/t5/operating-system-linux/perl-script-to-find-the-mx-records-for-a-given-domain/m-p/3955661#M95806</link>
      <description>&lt;!--!*#--&gt;Hi Arun,&lt;BR /&gt;&lt;BR /&gt;I wonder what's so bad about using Net::DNS&lt;BR /&gt;(maybe apart from that it requires a few other, but not exotic modules)?&lt;BR /&gt;&lt;BR /&gt;Of course you could reimplement the Domain protocol yourself, but I would consider this far from being easier than using Net::DNS ;-)&lt;BR /&gt;&lt;BR /&gt;For instance my ISP is the dreaded German dinosaur, and it provided me with this mail domain 't-online.de.'.&lt;BR /&gt;So I could query our caching Internet nameserver (with bogus 123.123.123.123) to get me all t-online mail exchangers.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;$ cat mx.pl&lt;BR /&gt;#!/usr/bin/perl&lt;BR /&gt;&lt;BR /&gt;use strict;&lt;BR /&gt;use warnings;&lt;BR /&gt;&lt;BR /&gt;use Net::DNS;&lt;BR /&gt;&lt;BR /&gt;my $res = Net::DNS::Resolver-&amp;gt;new(nameservers =&amp;gt; [qw(123.123.123.123)]);&lt;BR /&gt;&lt;BR /&gt;my $rr = $res-&amp;gt;query('t-online.de' =&amp;gt; 'MX');&lt;BR /&gt;&lt;BR /&gt;my @exchangers = map $_-&amp;gt;{exchange}, @{$rr-&amp;gt;{answer}};&lt;BR /&gt;&lt;BR /&gt;print join "\n", @exchangers, q{};&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;That would print this&lt;BR /&gt;(you could sort better by priority etc.)&lt;BR /&gt;&lt;BR /&gt;$ ./mx.pl       &lt;BR /&gt;mailin07.sul.t-online.de&lt;BR /&gt;mailin00.sul.t-online.de&lt;BR /&gt;mailin01.sul.t-online.de&lt;BR /&gt;mailin02.sul.t-online.de&lt;BR /&gt;mailin03.sul.t-online.de&lt;BR /&gt;mailin04.sul.t-online.de&lt;BR /&gt;mailin05.sul.t-online.de&lt;BR /&gt;mailin06.sul.t-online.de&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 05 Mar 2007 11:02:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/perl-script-to-find-the-mx-records-for-a-given-domain/m-p/3955661#M95806</guid>
      <dc:creator>Ralph Grothe</dc:creator>
      <dc:date>2007-03-05T11:02:00Z</dc:date>
    </item>
    <item>
      <title>Re: Perl script to find the MX records for a given domain</title>
      <link>https://community.hpe.com/t5/operating-system-linux/perl-script-to-find-the-mx-records-for-a-given-domain/m-p/3955662#M95807</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;As Net::DNS requires modules linked to it to be installed like Socket6,IPV6 and more, the problem occurs in installing all the modules.&lt;BR /&gt;&lt;BR /&gt;I used gethostbyname function which could get only few of the IP addresses for a given domain.&lt;BR /&gt;&lt;BR /&gt;So without Net::DNS and to avoid sequential installation of modules,would need a solution to find the MX records.&lt;BR /&gt;&lt;BR /&gt;Hope you could understand.&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Arun</description>
      <pubDate>Tue, 06 Mar 2007 01:05:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/perl-script-to-find-the-mx-records-for-a-given-domain/m-p/3955662#M95807</guid>
      <dc:creator>Arun Kumar Rajamari</dc:creator>
      <dc:date>2007-03-06T01:05:53Z</dc:date>
    </item>
    <item>
      <title>Re: Perl script to find the MX records for a given domain</title>
      <link>https://community.hpe.com/t5/operating-system-linux/perl-script-to-find-the-mx-records-for-a-given-domain/m-p/3955663#M95808</link>
      <description>&lt;!--!*#--&gt;Hi Arun,&lt;BR /&gt;&lt;BR /&gt;I understand your problems with Net::DNS.&lt;BR /&gt;Yes, it comes with an XS interface and needs some linking.&lt;BR /&gt;But it doesn't require IPv6 modules.&lt;BR /&gt;Our network is still IPv4 (I wonder who already  made the transition?).&lt;BR /&gt;From the README in my ~/.cpan/build/Net-DNS-0.59  directory I see that they claim these prerequisites&lt;BR /&gt;&lt;BR /&gt;     Test::More       &lt;BR /&gt;     IO::Socket      &lt;BR /&gt;     MIME::Base64     &lt;BR /&gt;     Digest::MD5  &lt;BR /&gt;     Digest::HMAC_MD5&lt;BR /&gt;     Net::IP&lt;BR /&gt;&lt;BR /&gt;If you have a build platform somewhere with an ANSI compliant C compiler the easiest way of installation there would be to&lt;BR /&gt;&lt;BR /&gt;# perl -MCPAN -e 'install Net::DNS'&lt;BR /&gt;&lt;BR /&gt;If this isn't possible for you &lt;BR /&gt;then you could just fork to the HP-UX implementation of nslookup and simply parse its output (though nslookup is quite a controversial tool while others like dig or host are probably to be preferred).&lt;BR /&gt;&lt;BR /&gt;Just to give you an (untested) idea how this could look like (plrease, refer to perldoc perlipc to find correct examples).&lt;BR /&gt;&lt;BR /&gt;e.g.&lt;BR /&gt;&lt;BR /&gt;my $nameserver = '123.123.123.123';&lt;BR /&gt;my $maildom = 'google.com.';&lt;BR /&gt;my $querytype = 'mx';&lt;BR /&gt;&lt;BR /&gt;my $pid = open NSPIPE, '-|';&lt;BR /&gt;die "Couldn't open pipe: $!" unless defined $pid;&lt;BR /&gt;if ($pid) {&lt;BR /&gt;   while (&lt;NSPIPE&gt;) {&lt;BR /&gt;       # parse here whatever feasible &lt;BR /&gt;       # from output of nslookup&lt;BR /&gt;   }&lt;BR /&gt;   close NSPIPE;&lt;BR /&gt;} else {&lt;BR /&gt;   exec '/usr/bin/nslookup', "-q=$querytype", $maildom, $nameserver;&lt;BR /&gt;   die "Couldn't exec nslookup: $!";&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;/NSPIPE&gt;</description>
      <pubDate>Tue, 06 Mar 2007 04:13:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/perl-script-to-find-the-mx-records-for-a-given-domain/m-p/3955663#M95808</guid>
      <dc:creator>Ralph Grothe</dc:creator>
      <dc:date>2007-03-06T04:13:53Z</dc:date>
    </item>
    <item>
      <title>Re: Perl script to find the MX records for a given domain</title>
      <link>https://community.hpe.com/t5/operating-system-linux/perl-script-to-find-the-mx-records-for-a-given-domain/m-p/3955664#M95809</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I used the system command in perl for executing the nslookup with MX option and working fine.&lt;BR /&gt;While doing nslookup in the command prompt,I am geting the following errors.&lt;BR /&gt;&lt;BR /&gt;Can't find server name for address &lt;BR /&gt;Non-existent host/domain&lt;BR /&gt;&lt;BR /&gt;In an assumption that the nslookup resolver/configuration file is not updated with the details,would like to transfer the nslookup query to alternative DNS server and get the result.&lt;BR /&gt;&lt;BR /&gt;Also how to do the same using Perl script&lt;BR /&gt;&lt;BR /&gt;default command in perl script is as follows&lt;BR /&gt;system(nslookup -type=MX google.com)&lt;BR /&gt;&lt;BR /&gt;So have to transfer the same to alternaive DNS server.&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Arun&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 24 Apr 2007 10:49:13 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/perl-script-to-find-the-mx-records-for-a-given-domain/m-p/3955664#M95809</guid>
      <dc:creator>Arun Kumar Rajamari</dc:creator>
      <dc:date>2007-04-24T10:49:13Z</dc:date>
    </item>
    <item>
      <title>Re: Perl script to find the MX records for a given domain</title>
      <link>https://community.hpe.com/t5/operating-system-linux/perl-script-to-find-the-mx-records-for-a-given-domain/m-p/3955665#M95810</link>
      <description>&lt;!--!*#--&gt;I'm not sure what you want to achieve.&lt;BR /&gt;But if it's the output of the nslookup command that you wish to capture, system() is most likely to be the wrong call,&lt;BR /&gt;unless you run it as a forked child to whom you set up a pipe to either stdin or stdout in advance (bidirectional communication would yet be another story).&lt;BR /&gt;But in this case one would fork and exec anyway, I would say.&lt;BR /&gt;The most simple way to capture a subprocess's output is by using the backticks or the qx delimiter.&lt;BR /&gt;e.g.&lt;BR /&gt;&lt;BR /&gt;my $nslookup_said = qw(/usr/bin/nslookup -q=mx google.com.);&lt;BR /&gt;&lt;BR /&gt;But beware, that this way you cannot avoid that Perl passes the qx() or backticked expression to the shell for expanding any meta characters.&lt;BR /&gt;This is inherently insecure, especially if the expression contains any user input.&lt;BR /&gt;&lt;BR /&gt;A better way would be to use a forked open and execute system() or exec() in the child's copy of the code.&lt;BR /&gt;This way you can pass any command and options or arguments as a list, thereby totally avoiding any shell execution.&lt;BR /&gt;&lt;BR /&gt;e.g.&lt;BR /&gt;&lt;BR /&gt;local *PH;&lt;BR /&gt;my $pid = open(PH, '-|');&lt;BR /&gt;die "Cannot open pipe to nslookup: $!\n" unless defined $pid;&lt;BR /&gt;my $nslookup_said;&lt;BR /&gt;if ($pid) {&lt;BR /&gt;   # let the parent read output from the child&lt;BR /&gt;   # assume moderate amount of output, and slurp&lt;BR /&gt;   local $/;&lt;BR /&gt;   $nslookup_said = &lt;PH&gt;;&lt;BR /&gt;   # parent will block until we close the pipe&lt;BR /&gt;   # note Perl will automatically fetch child's exit code&lt;BR /&gt;   # and place it in $?&lt;BR /&gt;   # releiving us from installing SIGCHLD handler&lt;BR /&gt;   close PH;&lt;BR /&gt;} else {&lt;BR /&gt;   exec qw(/usr/bin/nslookup -q=mx google.com.);&lt;BR /&gt;   # die is the only statement&lt;BR /&gt;   # that may follow an exec&lt;BR /&gt;   die "Cannot fork nslookup: $!\n";&lt;BR /&gt;}&lt;/PH&gt;</description>
      <pubDate>Tue, 24 Apr 2007 11:27:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/perl-script-to-find-the-mx-records-for-a-given-domain/m-p/3955665#M95810</guid>
      <dc:creator>Ralph Grothe</dc:creator>
      <dc:date>2007-04-24T11:27:20Z</dc:date>
    </item>
  </channel>
</rss>

