File: test.pl

package info (click to toggle)
libnet-arp-perl 1.0.12-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 180 kB
  • sloc: ansic: 315; perl: 43; makefile: 3
file content (56 lines) | stat: -rwxr-xr-x 1,554 bytes parent folder | download
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
54
55
56
#!/usr/bin/perl
#
# Perl ARP Extension test file
#
# Programmed by Bastian Ballmann
# Last update: 28.04.2020
#
# 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
{
    print "Requires real root privileges to build\n";
    exit 0;

    eval{ require Net::Pcap; };
              
    if($@ =~ /^Can\'t\slocate/)
    {
        $dev = "enp3s0f1";
    }
    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";