Wednesday, October 27, 2021

[SOLVED] Debian server "Can't locate loadable object" yet "Module is up to date"

Issue

I am trying to run a script on a Debian server that uses module Net::Pcap. The script works fine on all machines but this server, which happens to be the only one I NEED it to run on.

Upon running the script, I get the common "Can't locate loadable object for module Net::Pcap in @INC (path.. etc..)"

However, when I try to install using CPAN, I receive the message "Net::Pcap is up to date (0.16)."

I have manually removed Net::Pcap from all folders in @INC and reinstalled them both manually and through CPAN.

Anyone have a clue what my problem is?

For what it's worth, here is the code:

    use Net::Pcap;
    use NetPacket::TCP;
    use NetPacket::IP;
    use NetPacket::Ethernet;
    use Net::PcapUtils;

    open (TXT, ">", "data.txt");
    Net::PcapUtils::loop(\&process_packet,SNAPLEN => 65536,PROMISC => 1, );

    sub process_packet {
      my($user_data, $header, $packet) = @_;
      my $tcp_obj = NetPacket::TCP->decode($packet);
      my $ip_obj = NetPacket::IP->decode($packet);
      my $len = length $packet;
      my $i=0;
      print TXT "From: "."$ip_obj->{src_ip}".":"."$tcp_obj->{src_port}\n";
      print TXT "To: "."$ip_obj->{dest_ip}".":"."$tcp_obj->{dest_port}\n";
      do {    
        my $lg = substr $packet, $i, 16;
        printf TXT "%.8X : ", $i;
        $i+=16;
        print TXT unpack ('H2'x16, $lg), '  'x(16-length $lg);
        $lg =~ s/[\x00-\x1F\xFF]/./g;
        print TXT " $lg\n";
        } until $i>=$len;
        print TXT "\n";
      }
   close (TXT);

Solution

Maybe you are missing the native libs. Try to run as root:

apt-get install libnet-pcap-perl


Answered By - jjmontes