Implement rpcinfo command using perl and IO::Socket::INET
<p>I'm trying to emulate <code>rpcinfo -T udp -p $HOST</code> using perl.</p>

<p>It seems like I need to send some packets to port 111, but I could not find actual datagram from RFC 1833. <a href="https://www.rfc-editor.org/rfc/rfc1833.txt" rel="nofollow">https://www.rfc-editor.org/rfc/rfc1833.txt</a></p>

<p>I also found a script labeled <code>rpcinfo.pl</code> (<a href="https://stuff.mit.edu/afs/sipb/project/eichin/common/perl/nem/rpcinfo.pl" rel="nofollow">https://stuff.mit.edu/afs/sipb/project/eichin/common/perl/nem/rpcinfo.pl</a>) and copy the datagram part into my script below, but no luck.</p>

<p>My questions are: [1] Where can I find rpcinfo specification? [2] What's wrong with my following script?</p>

<p>Thanks.</p>

<pre><code>use strict;
use warnings;
use Carp;
use IO::Socket::INET;
use Data::Dumper;

my $remote_addr = $ARGV[0];

my $sock = IO::Socket::INET-&gt;new(
    Proto    =&gt; 'udp',
    PeerHost =&gt; $remote_addr,
    PeerPort =&gt; 111,
) or croak $@;

my $trx = int rand 10_000;
my $msg = pack(
    "N13",
    $trx,      # transaction
    0,         # call
    2,         # RPC version
    100000,    # portmap program number
    2,         # version number
    4,         # procedure number
);

$sock-&gt;send($msg) or croak "send() failed: $!\n";

my $resp = eval {
    local $SIG{ALRM} = sub { croak "Timed out"; };
    my $data;
    alarm 3;
    $sock-&gt;recv($data, 960) or croak "recv() failed: $!";
    alarm 0;
    return $data;
} || ();


print Dumper $resp;

1;
</code></pre>