File: test.pl

package info (click to toggle)
libnet-arp-perl 1.0.4-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze, wheezy
  • size: 180 kB
  • ctags: 181
  • sloc: ansic: 297; perl: 41; makefile: 26
file content (53 lines) | stat: -rwxr-xr-x 1,415 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/perl
#
# Perl ARP Extension test file
#
# Programmed by Bastian Ballmann
# Last update: 31.01.2007
#
# This program is free software; you can redistribute 
# it and/or modify it under the terms of the 
# GNU General Public License version 2 as published 
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will 
# be useful, but WITHOUT ANY WARRANTY; without even 
# the implied warranty of MERCHANTABILITY or FITNESS 
# FOR A PARTICULAR PURPOSE. 
# See the GNU General Public License for more details. 

use ExtUtils::testlib;
use Net::ARP;

BEGIN
{
    eval{ require Net::Pcap; };
              
    if($@ =~ /^Can\'t\slocate/)
    {
        $dev = "eth0";
    }
    else
    {
   	import Net::Pcap;
        $dev = Net::Pcap::lookupdev(\$errbuf);
    }
}

print "Sending ARP reply packet via dev $dev... ";

$ret = Net::ARP::send_packet($dev,                           # network interface
		      '127.0.0.1',                    # source ip
	              '127.0.0.1',                    # destination ip
		      'aa:bb:cc:aa:bb:cc',            # source mac
	              'ff:ff:ff:ff:ff:ff',            # destination mac
	              'reply');                       # ARP operation 

print $ret ? "ok\n" : "failed\n";

$mac = Net::ARP::get_mac($dev);
print "MAC $mac\n";

$mac = Net::ARP::arp_lookup($dev,"192.168.1.1");
print "192.168.1.1 has got mac $mac\n";