burningredmoon has asked for the wisdom of the Perl Monks concerning the following question:

I have a perl script that when I run it, it just hangs. I've gone through and tried several things. And now I'm thinking its the very first line.

#!/usr/bin/env perl use Net::PcapUtils; #packet cap module for WinPcap use NetPacket::Ethernet; use NetPacket::IP; use strict; use warnings; Net::PcapUtils::loop(\&process_pkt, SNAPLEN => 65536, #Size of packet. Can also use 0 PROMISC => 1, ); #Look at ALL packets sub process_pkt #Packet processing routine. { print(" hello Got a packet! "); my ($user_data,$hdr,$pkt)=@_; my $eth=NetPacket::Ethernet->decode($pkt); my $ip=NetPacket::IP->decode($eth->{data}); print(" $ip->{src_ip} $ip->{dest_ip} \n"); }
I have all the packages installed. When I type "where perl" in the command prompt it says C:\Perl\bin\perl.exe .

What should the first line be instead?

Replies are listed 'Best First'.
Re: Perl Script on Windows Vista
by ikegami (Patriarch) on Mar 28, 2011 at 21:03 UTC

    And now I'm thinking its the very first line.

    The shebang line is not used by Windows (although Perl itself will look for flag like "-w" in it). It is not the problem.

    I suspect it's not "hanging" so much as not seeing any packets for some reason.

      Thank you for the reply! Well that's good to know that its not that but I'm not sure why it doesn't see any packets either though.

      I'm working at home on a desktop with an Ethernet cable. Is there a way I can get the computer to receive packets? While it's running (looks like hanging) I try visting google and yahoo, just trying to get a packet. Am I going about that part the wrong way you think?

        You need to tell Net::Pcap (respectively Net::PcapUtils) about what device you want to capture packets on. For Windows, that is the (long and hard to type) full name of the device. Look at the output of

        use strict; use Data::Dumper; use Net::Pcap; Net::Pcap::findalldevs(\my %devinfo,\my $err); warn Dumper \%devinfo;

        or install Net::Pcap::FindDevice to conveniently get at devices by assigned IP address or network card name.