分类:
2007-11-19 17:49:19
#!/usr/bin/perl -w # Author: ruiqingzheng@gmail.com use strict; use Net::Frame::Simple; use Net::Frame::Dump::Online; use Net::ARP; use Net::Frame::Device; use Getopt::Std; my %opts; getopts('i:v', \%opts); die("Usage: $0\n". "\n". "-i interface\n". "-v be verbose\n". "") unless $opts{i}; my $device = Net::Frame::Device->new; my $onRecvCount = 100; #print $device -> dev; my $oDumpEvent = Net::Frame::Dump::Online -> new( dev => $device ->dev , filter => 'arp', onRecv => \&callOnRecv, onRecvCount => $onRecvCount, onRecvData => 'description', ); sub callOnRecv { my ($h,$data) = @_; #print "\nDescription: $data\n"; my $oSimple = Net::Frame::Simple -> newFromDump($h); my $srcIp = $oSimple -> ref -> {ARP} -> srcIp; my $dstIp = $oSimple -> ref -> {ARP} -> dstIp; my $opCode = $oSimple -> ref->{ARP} -> opCode; print $opCode . " from ".$srcIp ." To ".$dstIp."\n"; print $oSimple -> print . "\n" if $opts{v}; print "\n"; } $oDumpEvent -> start();
|