Skip to content

Instantly share code, notes, and snippets.

@jamesgolick
Created January 22, 2010 18:08
Show Gist options
  • Select an option

  • Save jamesgolick/283988 to your computer and use it in GitHub Desktop.

Select an option

Save jamesgolick/283988 to your computer and use it in GitHub Desktop.
sub send_arp($$) {
my $if = shift;
my $ip = shift;
if ($OSNAME eq 'linux') {
my $mac = '';
if ($Net::ARP::VERSION < 1.0) {
Net::ARP::get_mac($if, $mac);
}
else {
$mac = Net::ARP::get_mac($if);
}
return "ERROR: Couldn't get mac adress of interface $if" unless ($mac);
for (my $i = 0; $i < 5; $i++) {
Net::ARP::send_packet($if, $ip, $ip, $mac, 'ff:ff:ff:ff:ff:ff', 'request');
usleep(50);
Net::ARP::send_packet($if, $ip, $ip, $mac, 'ff:ff:ff:ff:ff:ff', 'reply');
usleep(50) if ($i < 4);
}
}
elsif ($OSNAME eq 'solaris') {
# Get params for send_arp
my $ipaddr = `/usr/sbin/ifconfig $if`;
# Get broadcast address and netmask
$ipaddr =~ /netmask\s*([0-9a-f]+)\s*broadcast\s*([\d\.]+)/i;
my $if_bcast = $1;
my $if_mask = $2;
`/bin/send_arp -i 100 -r 5 -p /tmp/send_arp $if $ip auto $if_bcast $if_mask`;
}
else {
_exit_error("ERROR: Unsupported platform!");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment