RawIP:无法发现MAC ADDRESS

时间:2018-03-17 09:04:21

标签: perl

我的环境是ubuntu。托管在digitalocean上的机器

以下是代码的一部分,并提供此错误:

  

无法发现157.5.172.182的MAC地址

#!/usr/bin/perl

use Net::RawIP;

($dest, $count, $port) = split(/\s+/, "@ARGV");
$opt = @ARGV;

print "+----------------------------------+\n";
print "Destination: $dest\n";
print "Source: Random\n";
print "Port: $port\n";
print "+----------------------------------+\n";

$saddr = join(".", map int rand 256, 1 .. 4);
$rsport = int rand(65535);

$packet =  Net::RawIP->new({
    ip => {
        saddr => $saddr,
        daddr => $dest,
    },

    udp => {
        source => $rsport,
        dest => $port,
        data => "\xFF\xFF\xFF\xFFping",
    },
});

$packet->send;
$packet->ethnew("eth0");
$packet->ethset(source => $saddr, dest => $dest);    
$packet->ethsend;
}

1 个答案:

答案 0 :(得分:0)

似乎arp_lookup函数用于获取mac地址不起作用,我不确定为什么,但是您可以(手动)执行以下操作:

use Net::ARP;

$dest_mac = "ff:ff:ff:ff:ff:ff";
$src_mac  = Net::ARP::get_mac("eth0");

$packet->ethnew("eth0");
$packet->ethset(source => $src_mac, dest => $dest_mac);