Created
November 2, 2020 10:27
-
-
Save odolezal/1029bfb88a72ea30ff9aa454728c3d27 to your computer and use it in GitHub Desktop.
log_ipv6-mac
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
#Skript se pripoji na router, stahne si ipv6 tabulku neibru a celou ji zaloguje i s pouzivanymi mac. Zivost adresy v tabulce je v minutach a defaultni hodnota je 4 hodiny. | |
my $router_ip="xxx.xxx.xxx.xxx"; | |
my $router_comm="xxxxx"; | |
use Net::SNMP; | |
use Data::Dumper; | |
use strict; | |
use Sys::Syslog; | |
openlog("dhcpd",,"local7"); | |
my $snmp=Net::SNMP->session(Hostname=>$router_ip,Community=>$router_comm,Version=>"v2c"); | |
if(!defined($snmp)) {exit 3;} | |
#nacteni mib abulky ipNetToPhysicalPhysAddress | |
my $data=$snmp->get_table(".1.3.6.1.2.1.4.35.1.4"); | |
foreach my $oid (keys %{$data}) { | |
my $mac; | |
my $ipv6; | |
if($oid=~/\.1\.3\.6\.1\.2\.1\.4\.35\.1\.4\..*(32\.1\.7\.24\.6\.3\.16\.[\d\.]*)$/) { | |
my @ipv6d=split(/\./,$1); | |
for(my $i=0;$i<@ipv6d;$i+=2) { | |
$ipv6.=sprintf("%x",$ipv6d[$i])."".sprintf("%02x",$ipv6d[$i+1]).":"; | |
} | |
chop($ipv6); | |
$mac=$data->{$oid}; | |
$mac=~s/([0-9a-f]{2})/\:$1/g; | |
$mac=~s/0x\:([0-9a-f\:]{17})/$1/g; | |
syslog("info","IPv6 to MAC: $ipv6 - $mac"); | |
} | |
} | |
$snmp->close; | |
closelog(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment