⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 arplogger.pl

📁 Network Administration Visualized 网络管理可视化源码
💻 PL
字号:
#!/usr/bin/env perl## Copyright 2001-2004 Norwegian University of Science and Technology## This file is part of Network Administration Visualized (NAV)## NAV is free software; you can redistribute it and/or modify# it under the terms of the GNU General Public License as published by# the Free Software Foundation; either version 2 of the License, or# (at your option) any later version.## NAV 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.## You should have received a copy of the GNU General Public License# along with NAV; if not, write to the Free Software# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA### $Id: $# Retrieves arp tables from network equipment and stores them in the# database.## Uses some code from test/arp by Simon Leinen. test/arp is# distributed with the Perl SNMP library by Simon Leinen# <simon@switch.ch> that we are using.## Authors: Stig Venaas <venaas@itea.ntnu.no>#          Gro-Anita Vindheim <grohi@itea.ntnu.no>###################### * asks the database for data (which gw's to get arp from++)# * asks each gw for it's # * checks with existing records in the database manage, the arp table#   - inserts new records unless already inserted#   - terminates old records where the ip<->mac comb. was not found #   - leave the rest unchangedrequire 5.002;use strict;use SNMP_Session "0.57"; use BER;use Pg;use NAV;use NAV::Path;my @arguments;my $filename;my $dbh;my $hostname;my $community;my $hostid;my $session;my %arptable;my %arptable_new;my $cursor;my $stat;my %prefiksdb;my %prefiks2boks;my %gwport;my %arpid;my %sysName;my $avsluttes;my $oppdat;my $nye;my $tot_avs=0;my $tot_oppdat=0;my $tot_nye=0;my %OIDS = (	    'ipNetToMediaPhysAddress' => [1,3,6,1,2,1,4,22,1,2],	    'ipNetToMediaType' => [1,3,6,1,2,1,4,22,1,4],	    );# Hente aktuelle rutere fra databasen.my $conn = NAV::connection("arplogger", "manage");my $sql = "SELECT netboxid,ip,ro,sysname FROM netbox WHERE catid IN ('GW', 'GSW') AND up='y'";my $resultat = NAV::select($conn, $sql);while(my @line = $resultat->fetchrow) {    push(@arguments,$line[0],$line[1],$line[2]);    $sysName{$line[0]} = $line[3];}$sql = "select netboxid,prefixid,host(netaddr) from gwportprefix join gwport using (gwportid) join module using (moduleid) join prefix using (prefixid)";$resultat = NAV::select($conn, $sql);while (my @line = $resultat->fetchrow) {    $prefiksdb{$line[2]} = $line[1];    $prefiks2boks{$line[1]} = $line[0];}$sql= "SELECT arpid,netboxid,ip,mac FROM arp WHERE end_time='infinity'"; $resultat = NAV::select($conn, $sql);while (my @line = $resultat->fetchrow) {    $arpid{$line[1]}{$line[2]}{$line[3]} = $line[0];    $arptable{$line[1]}{$line[2]} = $line[3];}# Main programwhile (@arguments) {    $avsluttes =0;    $oppdat = 0;    $nye = 0;    $hostid    = shift @arguments;      $hostname  = shift @arguments;    $community = shift @arguments;#    print "Henter fra $hostname\n";    print "Couldn't open SNMP session to $hostname\n" && next	unless ($session = SNMP_Session->open ($hostname, $community, 161));    %arptable_new = ();    $session->map_table ([$OIDS{'ipNetToMediaPhysAddress'}],			 \&process_arp_entry);    $session->close ();    # Avslutter records som ikke ble funnet p

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -