title: Getting all hostnames from IP address in Perl
body: <p>I'm trying to find a way to get all hostnames that resolve to an IP address.</p>
  
  <p>The gethostbyaddr function appears to only retrieve the first record from DNS (no matter if it's in scalar or list context).</p>
  
  <p>Example:</p>
  
  <pre><code>my $hostname = gethostbyaddr(inet_aton($ip_to_check), AF_INET);
  $print($hostname); //output: joe.example.com
  
  my @hostnames = gethostbyaddr(inet_aton($ip_to_check), AF_INET);
  foreach my $hostname (@hostnames){
   print "(", join(',',@hostnames), ")"; //output: (joe.example.com,,2,4,?)
  }
  </code></pre>
  
  <p>From the terminal:</p>
  
  <pre><code>$ host 192.168.1.5
  5.1.168.192.in-addr.arpa domain name pointer joe.example.com.
  5.1.168.192.in-addr.arpa domain name pointer john.example.com.
  </code></pre>
  
  <p>I've heard that Net::DNS is a little more robust, but I haven't had any luck getting that to pull all entries as well.</p>