WalkingZero has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w use Net::Pcap; my $dev="eth1"; my $address; my $netmask; my $err; if (Net::Pcap::lookupnet($dev, \$address, \$netmask, \$err)) { die 'Unable to look up device information for ', $dev, ' - ', $err +; } print "\n The Ip is $address and the mask is $netmask \n";
#!/usr/bin/perl -w use Net::ARP; use Net::Pcap; use NetPacket::Ethernet; use NetPacket::ARP; my $dev="eth1"; my $err; my $capobj=Net::Pcap::open_live($dev,1500,0,0,\$err); unless (defined $capobj){die 'Unable to create packet capture on devic +e ', $dev, ' - ', $err;} my $filter; Net::Pcap::compile($capobj, \$filter,'arp',0,'4294967040') && die 'Una +ble to compile packet capture filter'; Net::Pcap::setfilter($capobj, $filter) && die "Unable to set capture f +ilter!"; Net::ARP::send_packet("eth1","192.168.2.3","192.168.2.101","00:18:de:3 +4:8e:7b","ff:ff:ff:ff:ff:ff","request"); Net::Pcap::loop($capobj, -1 ,\&arp_packets,'') || die "Unable to comp +lete packet capture! \n"; Net::Pcap::close($capobj); sub arp_packets{ my ($user_data, $header, $packet)= @_; my $eth_obj=NetPacket::Ethernet::decode($packet); my $arp_obj=NetPacket::ARP::decode($eth_obj{'data'}, $eth_obj); print "Caught packet with source of $arp_obj->{'sha'} at ip $arp_obj-> +{'spa'} \n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Net::Pcap garbage Output
by GrandFather (Saint) on May 26, 2008 at 02:13 UTC | |
by WalkingZero (Sexton) on May 26, 2008 at 02:26 UTC | |
by GrandFather (Saint) on May 26, 2008 at 03:05 UTC | |
|
Re: Net::Pcap garbage Output
by almut (Canon) on May 26, 2008 at 02:31 UTC | |
by WalkingZero (Sexton) on May 26, 2008 at 02:38 UTC | |
by almut (Canon) on May 26, 2008 at 02:46 UTC | |
|
Re: Net::Pcap garbage Output
by Khen1950fx (Canon) on May 26, 2008 at 21:47 UTC |