Try this. It's a little better, but needs some work:-)

#!/usr/bin/perl use strict; use warnings; use Net::Pcap; use NetPacket::Ethernet; use NetPacket::IP; use NetPacket::TCP; my $err; my $type = 'DLT_IEEE802_11'; my $dev = Net::Pcap::lookupdev( \$err ); if ( defined $err ) { die "Unable to determine network device for monitoring - ", $err; } my ( $addr, $net, $mask ); if ( Net::Pcap::lookupnet( $dev, \$net, \$mask, \$err ) ) { die "Unable to look up device information for ", $dev, " - ", $err +; } print STDOUT "${dev}: addr/mask -> $addr/$mask\n"; my $WiFiobject = Net::Pcap::open_live( $dev, 2048, 1, -1, \$err ); my $w802 = Net::Pcap::datalink($type); Net::Pcap::set_datalink( $WiFiobject, $w802 ); unless ( defined $WiFiobject ) { die 'Unable to create packet capture on device ', $dev, ' - ', $er +r; } die 'Unable to perform packet capture' unless Net::Pcap::loop( $WiFiobject, -1, \&syn_packets, '' ); Net::Pcap::close($WiFiobject); sub syn_packets { my ( $user_data, $header, $packet ) = @_; my $macaddr = NetPacket::Ethernet->decode($packet); print "$macaddr->{'src_mac'}, $macaddr->{'dest_mac'}\n"; }

Update: Making some progress. This is better still. I added Net::Pcap::FindDevice

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; use Net::Pcap; use Net::Pcap::FindDevice; use NetPacket::Ethernet; use NetPacket::IP; use NetPacket::TCP; my $err; my $type = 'DLT_IEEE802_11'; my $dev = find_device($ARGV[0]); my ( $addr, $net, $mask ); if ( Net::Pcap::lookupnet( $dev, \$net, \$mask, \$err ) ) { die "Unable to look up device information for ", $dev, " - ", $err +; } print STDOUT "${dev}: addr/mask -> $addr/$mask\n"; my $WiFiobject = Net::Pcap::open_live( $dev, 128000, -1, 500, \$err ); my $w802 = Net::Pcap::datalink_name_to_val($type); Net::Pcap::set_datalink( $WiFiobject, $w802 ); unless ( defined $WiFiobject ) { die 'Unable to create packet capture on device ', $dev, ' - ', $er +r; } die 'Unable to perform packet capture' unless Net::Pcap::loop( $WiFiobject, -1, \&syn_packets, '' ); print Dumper ($WiFiobject); Net::Pcap::close($WiFiobject); sub syn_packets { my ( $user_data, $header, $packet ) = @_; my $macaddr = NetPacket::Ethernet->decode($packet); print "$macaddr->{'src_mac'}, $macaddr->{'dest_mac'}\n"; }

In reply to Re^5: Net::Pcap with wireless by Khen1950fx
in thread Net::Pcap with wireless by trevelyn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.