Chinaunix首页 | 论坛 | 博客
  • 博客访问: 543166
  • 博文数量: 119
  • 博客积分: 3167
  • 博客等级: 中校
  • 技术积分: 1215
  • 用 户 组: 普通用户
  • 注册时间: 2005-12-20 21:21
文章分类

全部博文(119)

文章存档

2015年(21)

2012年(4)

2011年(1)

2007年(11)

2006年(50)

2005年(32)

分类:

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();

运行效果:
root@juey-laptop:~/code# ./capArp.pl -i eth0 -v
1 from 192.168.1.111 To 192.168.1.117
ETH: dst:ff:ff:ff:ff:ff:ff  src:00:13:8f:2e:79:73  type:0x0806
ARP: hType:0x0001  pType:0x0800  hSize:0x06  pSize:0x04  opCode:0x0001
ARP: src:00:13:8f:2e:79:73  srcIp:192.168.1.111
ARP: dst:00:00:00:00:00:00  dstIp:192.168.1.117
Padding: 000000000000000000000000000000000000

1 from 192.168.1.111 To 192.168.1.116
ETH: dst:ff:ff:ff:ff:ff:ff  src:00:13:8f:2e:79:73  type:0x0806
ARP: hType:0x0001  pType:0x0800  hSize:0x06  pSize:0x04  opCode:0x0001
ARP: src:00:13:8f:2e:79:73  srcIp:192.168.1.111
ARP: dst:00:00:00:00:00:00  dstIp:192.168.1.116
Padding: 000000000000000000000000000000000000

1 from 192.168.1.111 To 192.168.1.115
ETH: dst:ff:ff:ff:ff:ff:ff  src:00:13:8f:2e:79:73  type:0x0806
ARP: hType:0x0001  pType:0x0800  hSize:0x06  pSize:0x04  opCode:0x0001
ARP: src:00:13:8f:2e:79:73  srcIp:192.168.1.111
ARP: dst:00:00:00:00:00:00  dstIp:192.168.1.115
Padding: 000000000000000000000000000000000000



阅读(2322) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~