1#!/usr/bin/perl
2#
3# $Id: arp-reply.pl 1640 2009-11-09 17:58:27Z gomor $
4#
5use strict;
6use warnings;
7
8use Getopt::Std;
9my %opts;
10getopts('m:M:i:a:d:v', \%opts);
11
12die "Usage: $0 -i dstIp -a isAtMac [-M srcMac] [-m dstMac] ".
13    "(or will broadcast) [-d device] [-v]\n"
14   unless $opts{i} && $opts{a};
15
16use Net::Packet;
17
18$Env->dev($opts{d}) if $opts{d};
19$Env->mac($opts{M}) if $opts{M};
20$Env->debug(3)      if $opts{v};
21$Env->noFrameAutoDump(1);
22
23my $eth = Net::Packet::ETH->new(
24   type => NP_ETH_TYPE_ARP,
25);
26$eth->dst($opts{m}) if $opts{m};
27
28my $arp = Net::Packet::ARP->new(
29   opCode => NP_ARP_OPCODE_REPLY,
30   src    => $opts{a},
31   srcIp  => $opts{i},
32   dstIp  => $opts{i},
33);
34$arp->dst($opts{m}) if $opts{m};
35
36my $frame = Net::Packet::Frame->new(l2 => $eth, l3 => $arp);
37
38print "Sending:\n";
39print $frame->l2->print, "\n";
40print $frame->l3->print, "\n";
41
42$frame->send;
43