#! /usr/bin/perl -w # (C) 2002 Carsten Groß - carsten /at/ siski.de # Polls the station WLAN List out of an ELSA LANCOM-L11 # generates a SSIable HTML table use strict; use Net::SNMP qw(snmp_dispatcher ticks_to_time); use POSIX qw(strftime); # User configurable things my $File = "/home/carsten/public_html/wlan-statistik.html"; my $host = "airolo.siski.de"; # TODO: Set your host my $password = 'sagichnicht'; # TODO: Set your password my ($session, $error) = Net::SNMP->session( -hostname => $host, -community => $password, -translate => [ -timeticks => 0x0 # Turn off so sysUpTime is numeric ] ); if (!defined $session) { print STDERR "SNMP-Error: $error\n"; exit 1; } my $WLANHostNumber = 1; # .iso.org.dod.internet.private.enterprises.2356.600.2.2.1.3.32.1. is the location of host info # (1.3.6.1.4.1.2356.600.2.2.1.3.32.1.) # of WLAN Hosts # .2.x = Age of the HOST x # .3.x = relative signal strength # .4.x = MAC Address # .6.x = RX Packets (@ Card :) ) # .7.x = TX Packets (@ Card :) ) # .9.x = "Comment field" my $MIBQuery = ".1.3.6.1.4.1.2356.600.2.2.1.3.32.1."; my $Status = 0; my $HostCount = 1; my $Currenttime = strftime "%d.%m.%Y %H:%M", localtime(time()); open (TF, ">$File.tmp") || die "Cannot open $File.tmp for writing: $!\n"; print TF "$Currenttime:
\n"; print TF < EOF print TF "HostAgeHost TX BytesHost RX BytesSignal Quality\n"; print TF "\n"; while ($Status == 0) { my @MIB = (); my $Host; my $Age; my $RX; my $TX; my $MAC; my $Signal; my $Align = qq| ALIGN="CENTER"|; my $Bad = qq| COLOR="RED"|; my $Avarage = qq| COLOR="YELLOW"|; my $Good = qq| COLOR="GREEN"|; foreach my $Value (qw(2 3 4 6 7 9)) { # 3 4 6 8 9)) { my $CurMib = "$MIBQuery" . $Value ."." . $HostCount; push @MIB, $CurMib; if ($Value == 2) { $Age = $CurMib; } elsif ($Value == 3) { $Signal = $CurMib; } elsif ($Value == 4) { $MAC = $CurMib; } elsif ($Value == 6) { $RX = $CurMib; } elsif ($Value == 7) { $TX = $CurMib; } elsif ($Value == 9) { $Host = $CurMib; } } my $result = $session->get_request( -varbindlist => \@MIB ); if (!defined $result) { $Status = 1; # Ende der Liste } else { print TF "\n"; my %h = %{$result}; print TF "" . $h{$Host} . "" . $h{$Age} . "\n"; print TF "" . $h{$TX}. "" . $h{$RX} . "\n"; print TF "". $h{$Signal} . "\n"; print TF "\n"; } $HostCount++; } if ($HostCount == 2) { print TF qq|\nNo hosts active\n\n|; } print TF "\n"; close(TF) || die "Cannot close $File.tmp: $!\n"; # remove old file! rename "$File.tmp", "$File"; exit 0;