#!/usr/bin/perl 


use Getopt::Std;
	       
# Port? This is the standard port#
my $port = 161;
my $ReverseTXRX;

my %opts; 
getopt("-ic", \%opts);
my $host = $opts{'i'} || Usage();
my $community = $opts{'c'} || Usage();
my $Percentage = 1;
my $MAX_RSSI = 40.0;

#################################################################
#---------------------- 4/22/2003 Earl -------------------------#
#################################################################

use Net::SNMP;
# use strict;

# Setup OIDs 
my $sysDescr =                   '1.3.6.1.4.1.410.1.1.1.1.0'; 
my $sysReset =                   '1.3.6.1.4.1.410.1.1.1.2.0'; 
my $sysTrapSwitch =              '1.3.6.1.4.1.410.1.1.1.3.0'; 
my $sysLoadDefaults =            '1.3.6.1.4.1.410.1.1.1.4.0'; 
my $sysDevInfo =                 '1.3.6.1.4.1.410.1.1.1.5.0';
my $sysUpload =                  '1.3.6.1.4.1.410.1.1.1.6.0';

my $operIPAddress =              '1.3.6.1.4.1.410.1.1.2.1.0';
my $operIPMask =                 '1.3.6.1.4.1.410.1.1.2.2.0';
my $operEthernetAddress =        '1.3.6.1.4.1.410.1.1.2.3.0';
my $operGateway =                '1.3.6.1.4.1.410.1.1.2.4.0';
my $operDHCP =                   '1.3.6.1.4.1.410.1.1.2.5.0';
my $operPrimaryPort =            '1.3.6.1.4.1.410.1.1.2.6.0';
my $operConfigurationPort =      '1.3.6.1.4.1.410.1.1.2.7.0';

my $operIPFilter          =      '1.3.6.1.4.1.410.1.1.3.1.0';
my $operForwardBcast      =      '1.3.6.1.4.1.410.1.1.3.2.0';
my $operSendBackBcast     =      '1.3.6.1.4.1.410.1.1.3.3.0';
my $operSendBackUnicast   =      '1.3.6.1.4.1.410.1.1.3.4.0';

my $bridgeOperationalMode =      '1.3.6.1.4.1.410.1.1.4.1.0';
my $bridgeRemoteBridgeBSSID =    '1.3.6.1.4.1.410.1.1.4.2.0';


my $EthRxStatistics =            '1.3.6.1.4.1.410.1.1.7.1.0'; 
my $EthTxStatistics =            '1.3.6.1.4.1.410.1.1.7.2.0'; 

my $TestModeOnOff =              '1.3.6.1.4.1.410.1.1.8.1.0'; 
my $TestModeCommandStructure  =  '1.3.6.1.4.1.410.1.1.8.2.0'; 
my $TestModeRadioConfiguration = '1.3.6.1.4.1.410.1.1.8.8.0'; 
my $TestModeStatistics     =     '1.3.6.1.4.1.410.1.1.8.9.0'; 

my $operChannelID =              '1.3.6.1.4.1.410.1.2.1.1.0';
my $operESSIDLength =            '1.3.6.1.4.1.410.1.2.1.2.0';
my $operESSID =                  '1.3.6.1.4.1.410.1.2.1.3.0';
my $operPreambleType =           '1.3.6.1.4.1.410.1.2.1.6.0';
my $operAuthenticationType =     '1.3.6.1.4.1.410.1.2.1.7.0';
 
my $wirelessStatistics =         '1.3.6.1.4.1.410.1.2.3.1.0';

my $ClientsNum =                 '1.3.6.1.4.1.410.1.2.5.1.0'; 
my $AssociatedSTAsInfo =         '1.3.6.1.4.1.410.1.2.5.2.0';

my $AuthorizedMacEnable =        '1.3.6.1.4.1.410.1.2.6.1.0';
my $AuthorizedMac =              '1.3.6.1.4.1.410.1.2.6.2.0';
my $AuthRadiusIP =               '1.3.6.1.4.1.410.1.2.6.3.0';
  
my $WirelessKnownAPs =           '1.3.6.1.4.1.410.1.2.7.1.0'; 

my $NetworkSettings =            '1.3.6.1.4.1.410.1.2.8.1.0'; 

my $OID = '1.3.6.1.4.1.410.1.2.8.1.0'; 
my $rxB = '1.3.6.1.4.1.410.1.1.7.1.0'; 
my $txB = '1.3.6.1.4.1.410.1.1.7.2.0'; 
my $Data = '00';
my $RBytes = '00';
my $TBytes = '00';
my $fileok = '00';
my $rxlb = 0;
my $rxhb = 0;
my $txlb = 0;
my $txhb = 0;
my $rtotal = 0;
my $ttotal = 0;
my $alltotal = 0;
my $Who = "Test";
my $mo = 0;

# Start the SNMP session
my ($session, $error) = Net::SNMP->session(
	    -hostname  => shift || $host,
             -community => shift || $community,
             -port      => shift || $port
          );


   $Data19 =snmpQuery($session,$sysDevInfo); 
   $devinfo = hex($Data19);
   $NOR   = snmpQuery($session,$sysDescr);
   $Data  = snmpQuery($session,$WirelessKnownAPs);
   $Data1 = snmpQuery($session,$wirelessStatistics);
   $Data2 = snmpQuery($session,$bridgeRemoteBridgeBSSID);
   $Data3 = snmpQuery($session,$ClientsNum);
   $Data4 = snmpQuery($session,$TestModeCommandStructure);
   $Data5 = snmpQuery($session,$bridgeOperationalMode);
   $Data6 = snmpQuery($session,$operChannelID);
   $Data7 = snmpQuery($session,$TestModeRadioConfiguration);
   $Data10 =snmpQuery($session,$EthRxStatistics); 
   $Data11 =snmpQuery($session,$EthTxStatistics); 
   $Data12 =snmpQuery($session,$operESSID); 
   $Data13 =snmpQuery($session,$operAuthenticationType); 
   $Data14 =snmpQuery($session,$operPreambleType); 
   $Data15 =snmpQuery($session,$AuthorizedMacEnable); 
   $Data17 =snmpQuery($session,$AuthRadiusIP); 
   $Data16 =snmpQuery($session,$AuthorizedMac); 
   $Data18 =snmpQuery($session,$NetworkSettings); 

$nam1 = substr($Data, 34, 32);
$d0hb = hex(substr($Data, 34, 1));
$d0lb = hex(substr($Data, 35, 1));
$d1hb = hex(substr($Data, 36, 1));
$d1lb = hex(substr($Data, 37, 1));
$d2hb = hex(substr($Data, 38, 1));
$d2lb = hex(substr($Data, 39, 1));
$d3hb = hex(substr($Data, 40, 1));
$d3lb = hex(substr($Data, 41, 1));
$d4hb = hex(substr($Data, 42, 1));
$d4lb = hex(substr($Data, 43, 1));
$d5hb = hex(substr($Data, 44, 1));
$d5lb = hex(substr($Data, 45, 1));
$d6hb = hex(substr($Data, 46, 1));
$d6lb = hex(substr($Data, 47, 1));
$d7hb = hex(substr($Data, 48, 1));
$d7lb = hex(substr($Data, 49, 1));
$nam1c1 = $d0lb + $d0hb * 16;
$nam1c2 = $d1lb + $d1hb * 16;
$nam1c1 = chr($nam1c1);
$nam1c2 = chr($nam1c2);
$nam1c3 = $d2lb + $d2hb * 16;
$nam1c4 = $d3lb + $d3hb * 16;
$nam1c3 = chr($nam1c3);
$nam1c4 = chr($nam1c4);
$nam1c5 = $d4lb + $d4hb * 16;
$nam1c6 = $d5lb + $d5hb * 16;
$nam1c5 = chr($nam1c5);
$nam1c6 = chr($nam1c6);
$nam1c7 = $d6lb + $d6hb * 16;
$nam1c8 = $d7lb + $d7hb * 16;
$nam1c7 = chr($nam1c7);
$nam1c8 = chr($nam1c8);
$nam1 = "$nam1c1$nam1c2$nam1c3$nam1c4$nam1c5$nam1c6$nam1c7$nam1c8";
$nam1c1 = 0;
$nam1c2 = 0;
$nam1c3 = 0;
$nam1c4 = 0;
$nam1c5 = 0;
$nam1c6 = 0;
$nam1c7 = 0;
$nam1c8 = 0;

$nam2 = substr($Data, 34+96, 32);
$d0hb = hex(substr($Data, 34+96, 1));
$d0lb = hex(substr($Data, 35+96, 1));
$d1hb = hex(substr($Data, 36+96, 1));
$d1lb = hex(substr($Data, 37+96, 1));
$d2hb = hex(substr($Data, 38+96, 1));
$d2lb = hex(substr($Data, 39+96, 1));
$d3hb = hex(substr($Data, 40+96, 1));
$d3lb = hex(substr($Data, 41+96, 1));
$d4hb = hex(substr($Data, 42+96, 1));
$d4lb = hex(substr($Data, 43+96, 1));
$d5hb = hex(substr($Data, 44+96, 1));
$d5lb = hex(substr($Data, 45+96, 1));
$d6hb = hex(substr($Data, 46+96, 1));
$d6lb = hex(substr($Data, 47+96, 1));
$d7hb = hex(substr($Data, 48+96, 1));
$d7lb = hex(substr($Data, 49+96, 1));
$nam1c1 = $d0lb + $d0hb * 16;
$nam1c2 = $d1lb + $d1hb * 16;
$nam1c1 = chr($nam1c1);
$nam1c2 = chr($nam1c2);
$nam1c3 = $d2lb + $d2hb * 16;
$nam1c4 = $d3lb + $d3hb * 16;
$nam1c3 = chr($nam1c3);
$nam1c4 = chr($nam1c4);
$nam1c5 = $d4lb + $d4hb * 16;
$nam1c6 = $d5lb + $d5hb * 16;
$nam1c5 = chr($nam1c5);
$nam1c6 = chr($nam1c6);
$nam1c7 = $d6lb + $d6hb * 16;
$nam1c8 = $d7lb + $d7hb * 16;
$nam1c7 = chr($nam1c7);
$nam1c8 = chr($nam1c8);
$nam2 = "$nam1c1$nam1c2$nam1c3$nam1c4$nam1c5$nam1c6$nam1c7$nam1c8";
$nam1c1 = 0;
$nam1c2 = 0;
$nam1c3 = 0;
$nam1c4 = 0;
$nam1c5 = 0;
$nam1c6 = 0;
$nam1c7 = 0;
$nam1c8 = 0;


$nam3 = substr($Data, 34+96+96, 32);
$d0hb = hex(substr($Data, 34+96+96, 1));
$d0lb = hex(substr($Data, 35+96+96, 1));
$d1hb = hex(substr($Data, 36+96+96, 1));
$d1lb = hex(substr($Data, 37+96+96, 1));
$d2hb = hex(substr($Data, 38+96+96, 1));
$d2lb = hex(substr($Data, 39+96+96, 1));
$d3hb = hex(substr($Data, 40+96+96, 1));
$d3lb = hex(substr($Data, 41+96+96, 1));
$d4hb = hex(substr($Data, 42+96+96, 1));
$d4lb = hex(substr($Data, 43+96+96, 1));
$d5hb = hex(substr($Data, 44+96+96, 1));
$d5lb = hex(substr($Data, 45+96+96, 1));
$d6hb = hex(substr($Data, 46+96+96, 1));
$d6lb = hex(substr($Data, 47+96+96, 1));
$d7hb = hex(substr($Data, 48+96+96, 1));
$d7lb = hex(substr($Data, 49+96+96, 1));
$nam1c1 = $d0lb + $d0hb * 16;
$nam1c2 = $d1lb + $d1hb * 16;
$nam1c1 = chr($nam1c1);
$nam1c2 = chr($nam1c2);
$nam1c3 = $d2lb + $d2hb * 16;
$nam1c4 = $d3lb + $d3hb * 16;
$nam1c3 = chr($nam1c3);
$nam1c4 = chr($nam1c4);
$nam1c5 = $d4lb + $d4hb * 16;
$nam1c6 = $d5lb + $d5hb * 16;
$nam1c5 = chr($nam1c5);
$nam1c6 = chr($nam1c6);
$nam1c7 = $d6lb + $d6hb * 16;
$nam1c8 = $d7lb + $d7hb * 16;
$nam1c7 = chr($nam1c7);
$nam1c8 = chr($nam1c8);
$nam3 = "$nam1c1$nam1c2$nam1c3$nam1c4$nam1c5$nam1c6$nam1c7$nam1c8";
$nam1c1 = 0;
$nam1c2 = 0;
$nam1c3 = 0;
$nam1c4 = 0;
$nam1c5 = 0;
$nam1c6 = 0;
$nam1c7 = 0;
$nam1c8 = 0;

$nam4 = substr($Data, 34+96+96+96, 32);
$d0hb = hex(substr($Data, 34+96+96+96, 1));
$d0lb = hex(substr($Data, 35+96+96+96, 1));
$d1hb = hex(substr($Data, 36+96+96+96, 1));
$d1lb = hex(substr($Data, 37+96+96+96, 1));
$d2hb = hex(substr($Data, 38+96+96+96, 1));
$d2lb = hex(substr($Data, 39+96+96+96, 1));
$d3hb = hex(substr($Data, 40+96+96+96, 1));
$d3lb = hex(substr($Data, 41+96+96+96, 1));
$d4hb = hex(substr($Data, 42+96+96+96, 1));
$d4lb = hex(substr($Data, 43+96+96+96, 1));
$d5hb = hex(substr($Data, 44+96+96+96, 1));
$d5lb = hex(substr($Data, 45+96+96+96, 1));
$d6hb = hex(substr($Data, 46+96+96+96, 1));
$d6lb = hex(substr($Data, 47+96+96+96, 1));
$d7hb = hex(substr($Data, 48+96+96+96, 1));
$d7lb = hex(substr($Data, 49+96+96+96, 1));
$nam1c1 = $d0lb + $d0hb * 16;
$nam1c2 = $d1lb + $d1hb * 16;
$nam1c1 = chr($nam1c1);
$nam1c2 = chr($nam1c2);
$nam1c3 = $d2lb + $d2hb * 16;
$nam1c4 = $d3lb + $d3hb * 16;
$nam1c3 = chr($nam1c3);
$nam1c4 = chr($nam1c4);
$nam1c5 = $d4lb + $d4hb * 16;
$nam1c6 = $d5lb + $d5hb * 16;
$nam1c5 = chr($nam1c5);
$nam1c6 = chr($nam1c6);
$nam1c7 = $d6lb + $d6hb * 16;
$nam1c8 = $d7lb + $d7hb * 16;
$nam1c7 = chr($nam1c7);
$nam1c8 = chr($nam1c8);
$nam4 = "$nam1c1$nam1c2$nam1c3$nam1c4$nam1c5$nam1c6$nam1c7$nam1c8";
$nam1c1 = 0;
$nam1c2 = 0;
$nam1c3 = 0;
$nam1c4 = 0;
$nam1c5 = 0;
$nam1c6 = 0;
$nam1c7 = 0;
$nam1c8 = 0;


$nam5 = substr($Data, 34+96+96+96+96, 32);
$d0hb = hex(substr($Data, 34+96+96+96+96, 1));
$d0lb = hex(substr($Data, 35+96+96+96+96, 1));
$d1hb = hex(substr($Data, 36+96+96+96+96, 1));
$d1lb = hex(substr($Data, 37+96+96+96+96, 1));
$d2hb = hex(substr($Data, 38+96+96+96+96, 1));
$d2lb = hex(substr($Data, 39+96+96+96+96, 1));
$d3hb = hex(substr($Data, 40+96+96+96+96, 1));
$d3lb = hex(substr($Data, 41+96+96+96+96, 1));
$d4hb = hex(substr($Data, 42+96+96+96+96, 1));
$d4lb = hex(substr($Data, 43+96+96+96+96, 1));
$d5hb = hex(substr($Data, 44+96+96+96+96, 1));
$d5lb = hex(substr($Data, 45+96+96+96+96, 1));
$d6hb = hex(substr($Data, 46+96+96+96+96, 1));
$d6lb = hex(substr($Data, 47+96+96+96+96, 1));
$d7hb = hex(substr($Data, 48+96+96+96+96, 1));
$d7lb = hex(substr($Data, 49+96+96+96+96, 1));
$nam1c1 = $d0lb + $d0hb * 16;
$nam1c2 = $d1lb + $d1hb * 16;
$nam1c1 = chr($nam1c1);
$nam1c2 = chr($nam1c2);
$nam1c3 = $d2lb + $d2hb * 16;
$nam1c4 = $d3lb + $d3hb * 16;
$nam1c3 = chr($nam1c3);
$nam1c4 = chr($nam1c4);
$nam1c5 = $d4lb + $d4hb * 16;
$nam1c6 = $d5lb + $d5hb * 16;
$nam1c5 = chr($nam1c5);
$nam1c6 = chr($nam1c6);
$nam1c7 = $d6lb + $d6hb * 16;
$nam1c8 = $d7lb + $d7hb * 16;
$nam1c7 = chr($nam1c7);
$nam1c8 = chr($nam1c8);
$nam5 = "$nam1c1$nam1c2$nam1c3$nam1c4$nam1c5$nam1c6$nam1c7$nam1c8";
$nam1c1 = 0;
$nam1c2 = 0;
$nam1c3 = 0;
$nam1c4 = 0;
$nam1c5 = 0;
$nam1c6 = 0;
$nam1c7 = 0;
$nam1c8 = 0;

$nam6 = substr($Data, 34+96+96+96+96+96, 32);
$d0hb = hex(substr($Data, 34+96+96+96+96+96, 1));
$d0lb = hex(substr($Data, 35+96+96+96+96+96, 1));
$d1hb = hex(substr($Data, 36+96+96+96+96+96, 1));
$d1lb = hex(substr($Data, 37+96+96+96+96+96, 1));
$d2hb = hex(substr($Data, 38+96+96+96+96+96, 1));
$d2lb = hex(substr($Data, 39+96+96+96+96+96, 1));
$d3hb = hex(substr($Data, 40+96+96+96+96+96, 1));
$d3lb = hex(substr($Data, 41+96+96+96+96+96, 1));
$d4hb = hex(substr($Data, 42+96+96+96+96+96, 1));
$d4lb = hex(substr($Data, 43+96+96+96+96+96, 1));
$d5hb = hex(substr($Data, 44+96+96+96+96+96, 1));
$d5lb = hex(substr($Data, 45+96+96+96+96+96, 1));
$d6hb = hex(substr($Data, 46+96+96+96+96+96, 1));
$d6lb = hex(substr($Data, 47+96+96+96+96+96, 1));
$d7hb = hex(substr($Data, 48+96+96+96+96+96, 1));
$d7lb = hex(substr($Data, 49+96+96+96+96+96, 1));
$nam1c1 = $d0lb + $d0hb * 16;
$nam1c2 = $d1lb + $d1hb * 16;
$nam1c1 = chr($nam1c1);
$nam1c2 = chr($nam1c2);
$nam1c3 = $d2lb + $d2hb * 16;
$nam1c4 = $d3lb + $d3hb * 16;
$nam1c3 = chr($nam1c3);
$nam1c4 = chr($nam1c4);
$nam1c5 = $d4lb + $d4hb * 16;
$nam1c6 = $d5lb + $d5hb * 16;
$nam1c5 = chr($nam1c5);
$nam1c6 = chr($nam1c6);
$nam1c7 = $d6lb + $d6hb * 16;
$nam1c8 = $d7lb + $d7hb * 16;
$nam1c7 = chr($nam1c7);
$nam1c8 = chr($nam1c8);
$nam6 = "$nam1c1$nam1c2$nam1c3$nam1c4$nam1c5$nam1c6$nam1c7$nam1c8";
$nam1c1 = 0;
$nam1c2 = 0;
$nam1c3 = 0;
$nam1c4 = 0;
$nam1c5 = 0;
$nam1c6 = 0;
$nam1c7 = 0;
$nam1c8 = 0;


$mo = oct($Data5);
 
 if ($mo == 1) {$Data5 = "Point to Multi-Point";
  }
 if ($mo == 2) {$Data5 = "AP";
  }
 if ($mo == 3) {$Data5 = "AP Client";
  }
 if ($mo == 4) {$Data5 = "Point to Point";
  }
 if ($mo == 5) {$Data5 = "Repeater";
  }
 
$auth = oct($Data13);
 
 if ($auth == 1) {$Data13 = "Open System";
  }
 if ($auth == 2) {$Data13 = "Shared Key";
  }
 if ($auth == 3) {$Data13 = "Both Types";
  }
 
$preamble = oct($Data14);
 
 if ($preamble == 1) {$Data14 = "Short";
  }
 if ($preamble == 2) {$Data14 = "Long";
  }

$MacEn = oct($Data15);
 
 if ($MacEn == 1) {$Data15 = "Enabled";
  }
 if ($MacEn == 2) {$Data15 = "Disabled";
  }

$IP1 = substr($Data,2,12);

$d0hb = hex(substr($Data, 14, 1));
$d0lb = hex(substr($Data, 15, 1));
$d1hb = hex(substr($Data, 16, 1));
$d1lb = hex(substr($Data, 17, 1));
$rssi1total = $d0lb + $d0hb * 16;
$lq1total = $d1lb + $d1hb * 16;

  {
 if ( $Percentage == 1 ) {
    $rssi = $rssi1total;
    $link = $lq1total;
    if ($rssi > $MAX_RSSI) {
      $rssi = 40;
    }
    if ($link > $MAX_RSSI) {
      $link = 40;
    }
    $linkvalue = ($MAX_RSSI - $link);
    $rssi1total = ( $rssi / $MAX_RSSI ) * 100;
    $lq1total = ( $linkvalue / $MAX_RSSI ) * 100;
  }

}
$rssi1total = int($rssi1total);
$lq1total = int($lq1total);

$d0hb = hex(substr($Data, 14+96, 1));
$d0lb = hex(substr($Data, 15+96, 1));
$d1hb = hex(substr($Data, 16+96, 1));
$d1lb = hex(substr($Data, 17+96, 1));
$rssi2total = $d0lb + $d0hb * 16;
$lq2total = $d1lb + $d1hb * 16;

  {
 if ( $Percentage == 1 ) {
    $rssi = $rssi2total;
    $link = $lq2total;
    if ($rssi > $MAX_RSSI) {
      $rssi = 40;
    }
    if ($link > $MAX_RSSI) {
      $link = 40;
    }
    $linkvalue = ($MAX_RSSI - $link);
    $rssi2total = ( $rssi / $MAX_RSSI ) * 100;
    $lq2total = ( $linkvalue / $MAX_RSSI ) * 100;
  }

}

$rssi2total = int($rssi2total);
$lq2total = int($lq2total);

$IP2 = substr($Data,2+96,12);

$d0hb = hex(substr($Data, 14+96+96, 1));
$d0lb = hex(substr($Data, 15+96+96, 1));
$d1hb = hex(substr($Data, 16+96+96, 1));
$d1lb = hex(substr($Data, 17+96+96, 1));
$rssi3total = $d0lb + $d0hb * 16;
$lq3total = $d1lb + $d1hb * 16;

   {
  if ( $Percentage == 1 ) {
     $rssi = $rssi3total;
     $link = $lq3total;
     if ($rssi > $MAX_RSSI) {
       $rssi = 40;
     }
     if ($link > $MAX_RSSI) {
       $link = 40;
     }
     $linkvalue = ($MAX_RSSI - $link);
     $rssi3total = ( $rssi / $MAX_RSSI ) * 100;
     $lq3total = ( $linkvalue / $MAX_RSSI ) * 100;
   }
 
 }
$rssi3total = int($rssi3total);
$lq3total = int($lq3total);

$IP3 = substr($Data,2+96+96,12);

$d0hb = hex(substr($Data, 14+96+96+96, 1));
$d0lb = hex(substr($Data, 15+96+96+96, 1));
$d1hb = hex(substr($Data, 16+96+96+96, 1));
$d1lb = hex(substr($Data, 17+96+96+96, 1));
$rssi4total = $d0lb + $d0hb * 16;
$lq4total = $d1lb + $d1hb * 16;

  {
 if ( $Percentage == 1 ) {
    $rssi = $rssi4total;
    $link = $lq4total;
    if ($rssi > $MAX_RSSI) {
      $rssi = 40;
    }
    if ($link > $MAX_RSSI) {
      $link = 40;
    }
    $linkvalue = ($MAX_RSSI - $link);
    $rssi4total = ( $rssi / $MAX_RSSI ) * 100;
    $lq4total = ( $linkvalue / $MAX_RSSI ) * 100;
  }

}
$rssi4total = int($rssi4total);
$lq4total = int($lq4total);

$IP4 = substr($Data,2+96+96+96,12);

$d0hb = hex(substr($Data, 14+96+96+96+96, 1));
$d0lb = hex(substr($Data, 15+96+96+96+96, 1));
$d1hb = hex(substr($Data, 16+96+96+96+96, 1));
$d1lb = hex(substr($Data, 17+96+96+96+96, 1));
$rssi5total = $d0lb + $d0hb * 16;
$lq5total = $d1lb + $d1hb * 16;

  {
 if ( $Percentage == 1 ) {
    $rssi = $rssi5total;
    $link = $lq5total;
    if ($rssi > $MAX_RSSI) {
      $rssi = 40;
    }
    if ($link > $MAX_RSSI) {
      $link = 40;
    }
    $linkvalue = ($MAX_RSSI - $link);
    $rssi5total = ( $rssi / $MAX_RSSI ) * 100;
    $lq5total = ( $linkvalue / $MAX_RSSI ) * 100;
  }

}

$rssi5total = int($rssi5total);
$lq5total = int($lq5total);

$IP5 = substr($Data,2+96+96+96+96,12);

$d0hb = hex(substr($Data, 14+96+96+96+96+96, 1));
$d0lb = hex(substr($Data, 15+96+96+96+96+96, 1));
$d1hb = hex(substr($Data, 16+96+96+96+96+96, 1));
$d1lb = hex(substr($Data, 17+96+96+96+96+96, 1));
$rssi6total = $d0lb + $d0hb * 16;
$lq6total = $d1lb + $d1hb * 16;

  {
 if ( $Percentage == 1 ) {
    $rssi = $rssi6total;
    $link = $lq6total;
    if ($rssi > $MAX_RSSI) {
      $rssi = 40;
    }
    if ($link > $MAX_RSSI) {
      $link = 40;
    }
    $linkvalue = ($MAX_RSSI - $link);
    $rssi6total = ( $rssi / $MAX_RSSI ) * 100;
    $lq6total = ( $linkvalue / $MAX_RSSI ) * 100;
  }

}

$rssi6total = int($rssi6total);
$lq6total = int($lq6total);

$IP6 = substr($Data,2+96+96+96+96+96,12);


$Data7 = substr($Data7,2,32);
$ch1pwr = substr($Data7,0,2);
$ch2pwr = substr($Data7,2,2);
$ch3pwr = substr($Data7,4,2);
$ch4pwr = substr($Data7,6,2);
$ch5pwr = substr($Data7,8,2);
$ch6pwr = substr($Data7,10,2);
$ch7pwr = substr($Data7,12,2);
$ch8pwr = substr($Data7,14,2);
$ch9pwr = substr($Data7,16,2);
$ch10pwr = substr($Data7,18,2);
$ch11pwr = substr($Data7,20,2);
$ch12pwr = substr($Data7,22,2);
$ch13pwr = substr($Data7,24,2);
$ch14pwr = substr($Data7,26,2);


    print "Site Survey Program for Atmel Chipset Radios";
    print " \n";
    print "(SmartBridges APPO , D-Link DWL-900AP)";
    print " \n";
    print "by Earl Campbell - UpHi.net 08/23/2003";
    print " \n";
    print " \n";
    print "Name of Radio     ",$NOR;
    print " \n";
    print "Num Asoc Stations ",$Data3;
    print " \n";
    print "On Channel        ",$ch;
    print " \n";
    print "In Mode           ",$Data5;
    print " \n";
    print "Connected ESSID   ",$Data12;
    print " \n";
    print "PreAmble Type     ",$Data14;
    print " \n";
    print "Auth Type         ",$Data13;
    print " \n";
    print "Mac Enable        ",$Data15;
    print " \n";
    print "Mac IP            ",$Data16;
    print " \n";
    print "Radius Server IP  ",$Data17;
    print " \n";
    print "Network Settings  ",$Data18;
    print " \n";
    print " \n";
    print "CR31 Power Regs Min 0----(Max)80----FF Min  ";
    print " \n";
    
print "  Ch 1                       ",$ch1pwr;
    print " \n";
print "  Ch 2                       ",$ch2pwr;
    print " \n";
print "  Ch 3                       ",$ch3pwr;
    print " \n";
print "  Ch 4                       ",$ch4pwr;
    print " \n";
print "  Ch 5                       ",$ch5pwr;
    print " \n";
print "  Ch 6                       ",$ch6pwr;
    print " \n";
print "  Ch 7                       ",$ch7pwr;
    print " \n";
print "  Ch 8                       ",$ch8pwr;
    print " \n";
print "  Ch 9                       ",$ch9pwr;
    print " \n";
print "  Ch 10                      ",$ch10pwr;
    print " \n";
print "  Ch 11                      ",$ch11pwr;
    print " \n";
print "  Ch 12                      ",$ch12pwr;
    print " \n";
print "  Ch 13                      ",$ch13pwr;
    print " \n"     ;
print "  Ch 14                      ",$ch14pwr;
    print " \n";

    print " \n";

    print "Site 1            ",$IP1," ",$nam1;
    print " \n";
    print "RSSI %            ",$rssi1total;
    print " \n";
    print "Link %            ",$lq1total;
    print " \n";
    print " \n";
 
    print "Site 2            ",$IP2," ",$nam2;
    print " \n";
    print "RSSI %            ",$rssi2total;
    print " \n";
    print "Link %            ",$lq2total;
    print " \n";
    print " \n";
 
    print "Site 3            ",$IP3," ",$nam3;
    print " \n";
    print "RSSI %            ",$rssi3total;
    print " \n";
    print "Link %            ",$lq3total;
    print " \n";
    print " \n";
 
    print "Site 4            ",$IP4," ",$nam4;
    print " \n";
    print "RSSI %            ",$rssi4total;
    print " \n";
    print "Link %            ",$lq4total;
    print " \n";
    print " \n";

    print "Site 5            ",$IP5," ",$nam5;
    print " \n";
    print "RSSI %            ",$rssi5total;
    print " \n";
    print "Link %            ",$lq5total;
    print " \n";
    print " \n";
 
    print "Site 6            ",$IP6," ",$nam6;
    print " \n";
    print "RSSI %            ",$rssi6total;
    print " \n";
    print "Link %            ",$lq6total;
    print " \n";
    print " \n";
 
    print "Data for IP       ",$host;
    print " \n";
  
    my ($session, $error) = Net::SNMP->session(
	    -hostname  => shift || $host,
             -community => shift || $community,
             -port      => shift || $port
          );
   $Data19 =snmpQuery($session,$sysDevInfo); 
   $Data20 =snmpQuery($session,$operIPAddress); 
   $Data21 =snmpQuery($session,$operIPMask); 
   $Data22 =snmpQuery($session,$operEthernetAddress); 
   $Data23 =snmpQuery($session,$operGateway); 
   $Data24 =snmpQuery($session,$operDHCP); 
   $Data25 =snmpQuery($session,$operPrimaryPort); 
   $Data26 =snmpQuery($session,$operConfigurationPort); 
   print "MAC Address       ";
   print substr($Data19,10,12);
    print " \n";
 
$namSys = substr($Data19,42, 64);

$s1 = substr($namSys,0, 2);
$s2 = substr($namSys,2, 2);
$s3 = substr($namSys,4, 2);
$s4 = substr($namSys,6, 2);
$s5 = substr($namSys,8, 2);
$s6 = substr($namSys,10, 2);
$s7 = substr($namSys,12, 2);
$s8 = substr($namSys,14, 2);
$s9 = substr($namSys,16, 2);
$s10 = substr($namSys,18, 2);
$s11 = substr($namSys,20, 2);
$s12 = substr($namSys,22, 2);
$s13 = substr($namSys,24, 2);
$s14 = substr($namSys,26, 2);
$s15 = substr($namSys,28, 2);
$s16 = substr($namSys,30, 2);
$s17 = substr($namSys,32, 2);
$s18 = substr($namSys,34, 2);
$s19 = substr($namSys,36, 2);
$s20 = substr($namSys,38, 2);
$s21 = substr($namSys,40, 2);
$s22 = substr($namSys,42, 2);
$s23 = substr($namSys,44, 2);
$s24 = substr($namSys,46, 2);
$s25 = substr($namSys,48, 2);
$s26 = substr($namSys,50, 2);
$s27 = substr($namSys,52, 2);
$s28 = substr($namSys,54, 2);
$s29 = substr($namSys,56, 2);
$s30 = substr($namSys,58, 2);
$s31 = substr($namSys,60, 2);
$s32 = substr($namSys,62, 2);

    print "Mfg Dev Info      ";
    print chr(hex($s1)),chr(hex($s2)),chr(hex($s3)),chr(hex($s4)),chr(hex($s5)),chr(hex($s6)),chr(hex($s7)),chr(hex($s8));
    print chr(hex($s9)),chr(hex($s10)),chr(hex($s11)),chr(hex($s12)),chr(hex($s13)),chr(hex($s14)),chr(hex($s15)),chr(hex($s16));
    print chr(hex($s17)),chr(hex($s18)),chr(hex($s19)),chr(hex($s20)),chr(hex($s21)),chr(hex($s22)),chr(hex($s23)),chr(hex($s24));
    print chr(hex($s25)),chr(hex($s26)),chr(hex($s27)),chr(hex($s28)),chr(hex($s29)),chr(hex($s30)),chr(hex($s31)),chr(hex($s32));
    print " \n";
  
 $ProductName = substr($Data19,114, 64);

$s1 = substr($ProductName,0, 2);
$s2 = substr($ProductName,2, 2);
$s3 = substr($ProductName,4, 2);
$s4 = substr($ProductName,6, 2);
$s5 = substr($ProductName,8, 2);
$s6 = substr($ProductName,10, 2);
$s7 = substr($ProductName,12, 2);
$s8 = substr($ProductName,14, 2);
$s9 = substr($ProductName,16, 2);
$s10 = substr($ProductName,18, 2);
$s11 = substr($ProductName,20, 2);
$s12 = substr($ProductName,22, 2);
$s13 = substr($ProductName,24, 2);
$s14 = substr($ProductName,26, 2);
$s15 = substr($ProductName,28, 2);
$s16 = substr($ProductName,30, 2);
$s17 = substr($ProductName,32, 2);
$s18 = substr($ProductName,34, 2);
$s19 = substr($ProductName,36, 2);
$s20 = substr($ProductName,38, 2);
$s21 = substr($ProductName,40, 2);
$s22 = substr($ProductName,42, 2);
$s23 = substr($ProductName,44, 2);
$s24 = substr($ProductName,46, 2);
$s25 = substr($ProductName,48, 2);
$s26 = substr($ProductName,50, 2);
$s27 = substr($ProductName,52, 2);
$s28 = substr($ProductName,54, 2);
$s29 = substr($ProductName,56, 2);
$s30 = substr($ProductName,58, 2);
$s31 = substr($ProductName,60, 2);
$s32 = substr($ProductName,62, 2);

    print "Product Name      ";
    print chr(hex($s1)),chr(hex($s2)),chr(hex($s3)),chr(hex($s4)),chr(hex($s5)),chr(hex($s6)),chr(hex($s7)),chr(hex($s8));
    print chr(hex($s9)),chr(hex($s10)),chr(hex($s11)),chr(hex($s12)),chr(hex($s13)),chr(hex($s14)),chr(hex($s15)),chr(hex($s16));
    print chr(hex($s17)),chr(hex($s18)),chr(hex($s19)),chr(hex($s20)),chr(hex($s21)),chr(hex($s22)),chr(hex($s23)),chr(hex($s24));
    print chr(hex($s25)),chr(hex($s26)),chr(hex($s27)),chr(hex($s28)),chr(hex($s29)),chr(hex($s30)),chr(hex($s31)),chr(hex($s32));
    print " \n";
    print " \n";
  
# Break it down into the AT76C510MIB Lables for WirelessStatitcs group   

print "Wireless Stats";
    print " \n";
    print " \n";

$UnicastTransmittedPackets = substr($Data1,2,8);
$Total = "0";
$conv = $UnicastTransmittedPackets;
$d0hb = hex(substr($conv, 0, 1));
$d0lb = hex(substr($conv, 1, 1));
$d1hb = hex(substr($conv, 2, 1));
$d1lb = hex(substr($conv, 3, 1));
$d2hb = hex(substr($conv, 4, 1));
$d2lb = hex(substr($conv, 5, 1));
$d3hb = hex(substr($conv, 6, 1));
$d3lb = hex(substr($conv, 7, 1));
$H1 = $d0lb + $d0hb * 16;
$L1 = $d1lb * 256 + ($d1hb * 4096);
$H2 = ($d2lb * 65536) + ($d2hb * (65536 * 16));
$L2 = ($d3lb * (65536 * 256)) + ($d3hb * (65536 * 4096));
$Total = ($L1) + ($H1) + ($L2) + ($H2);

    print "UnicastTransmittedPackets   ",$Total;
    print " \n";
    
$BroadcastTransmittedPackets = substr($Data1,10,8);
$Total = "0";
$conv = $BroadcastTransmittedPackets;
$d0hb = hex(substr($conv, 0, 1));
$d0lb = hex(substr($conv, 1, 1));
$d1hb = hex(substr($conv, 2, 1));
$d1lb = hex(substr($conv, 3, 1));
$d2hb = hex(substr($conv, 4, 1));
$d2lb = hex(substr($conv, 5, 1));
$d3hb = hex(substr($conv, 6, 1));
$d3lb = hex(substr($conv, 7, 1));
$H1 = $d0lb + $d0hb * 16;
$L1 = $d1lb * 256 + ($d1hb * 4096);
$H2 = ($d2lb * 65536) + ($d2hb * (65536 * 16));
$L2 = ($d3lb * (65536 * 256)) + ($d3hb * (65536 * 4096));
$Total = ($L1) + ($H1) + ($L2) + ($H2);

    print "BroadcastTransmittedPackets ",$Total;
    print " \n";

$MulticastTransmittedPackets = substr($Data1,18,8);
$Total = "0";
$conv = $MulticastTransmittedPackets;
$d0hb = hex(substr($conv, 0, 1));
$d0lb = hex(substr($conv, 1, 1));
$d1hb = hex(substr($conv, 2, 1));
$d1lb = hex(substr($conv, 3, 1));
$d2hb = hex(substr($conv, 4, 1));
$d2lb = hex(substr($conv, 5, 1));
$d3hb = hex(substr($conv, 6, 1));
$d3lb = hex(substr($conv, 7, 1));
$H1 = $d0lb + $d0hb * 16;
$L1 = $d1lb * 256 + ($d1hb * 4096);
$H2 = ($d2lb * 65536) + ($d2hb * (65536 * 16));
$L2 = ($d3lb * (65536 * 256)) + ($d3hb * (65536 * 4096));
$Total = ($L1) + ($H1) + ($L2) + ($H2);
    print "MulticastTransmittedPackets ",$Total;
    print " \n";
    
$TransmittedBeacon = substr($Data1,26,8);
$Total = "0";
$conv = $TransmittedBeacon;
$d0hb = hex(substr($conv, 0, 1));
$d0lb = hex(substr($conv, 1, 1));
$d1hb = hex(substr($conv, 2, 1));
$d1lb = hex(substr($conv, 3, 1));
$d2hb = hex(substr($conv, 4, 1));
$d2lb = hex(substr($conv, 5, 1));
$d3hb = hex(substr($conv, 6, 1));
$d3lb = hex(substr($conv, 7, 1));
$H1 = $d0lb + $d0hb * 16;
$L1 = $d1lb * 256 + ($d1hb * 4096);
$H2 = ($d2lb * 65536) + ($d2hb * (65536 * 16));
$L2 = ($d3lb * (65536 * 256)) + ($d3hb * (65536 * 4096));
$Total = ($L1) + ($H1) + ($L2) + ($H2);
    print "TransmittedBeacon           ",$Total;
    print " \n";
    
$TransmittedACK = substr($Data1,34,8);
$Total = "0";
$conv = $TransmittedACK;
$d0hb = hex(substr($conv, 0, 1));
$d0lb = hex(substr($conv, 1, 1));
$d1hb = hex(substr($conv, 2, 1));
$d1lb = hex(substr($conv, 3, 1));
$d2hb = hex(substr($conv, 4, 1));
$d2lb = hex(substr($conv, 5, 1));
$d3hb = hex(substr($conv, 6, 1));
$d3lb = hex(substr($conv, 7, 1));
$H1 = $d0lb + $d0hb * 16;
$L1 = $d1lb * 256 + ($d1hb * 4096);
$H2 = ($d2lb * 65536) + ($d2hb * (65536 * 16));
$L2 = ($d3lb * (65536 * 256)) + ($d3hb * (65536 * 4096));
$Total = ($L1) + ($H1) + ($L2) + ($H2);
    print "TransmittedACK              ",$Total;
    print " \n";
    
$TransmittedRTS = substr($Data1,42,8);
$Total = "0";
$conv = $TransmittedRTS;
$d0hb = hex(substr($conv, 0, 1));
$d0lb = hex(substr($conv, 1, 1));
$d1hb = hex(substr($conv, 2, 1));
$d1lb = hex(substr($conv, 3, 1));
$d2hb = hex(substr($conv, 4, 1));
$d2lb = hex(substr($conv, 5, 1));
$d3hb = hex(substr($conv, 6, 1));
$d3lb = hex(substr($conv, 7, 1));
$H1 = $d0lb + $d0hb * 16;
$L1 = $d1lb * 256 + ($d1hb * 4096);
$H2 = ($d2lb * 65536) + ($d2hb * (65536 * 16));
$L2 = ($d3lb * (65536 * 256)) + ($d3hb * (65536 * 4096));
$Total = ($L1) + ($H1) + ($L2) + ($H2);
    print "TransmittedRTS              ",$Total;
    print " \n";
    
$TransmittedCTS = substr($Data1,50,8);
$Total = "0";
$conv = $TransmittedCTS;
$d0hb = hex(substr($conv, 0, 1));
$d0lb = hex(substr($conv, 1, 1));
$d1hb = hex(substr($conv, 2, 1));
$d1lb = hex(substr($conv, 3, 1));
$d2hb = hex(substr($conv, 4, 1));
$d2lb = hex(substr($conv, 5, 1));
$d3hb = hex(substr($conv, 6, 1));
$d3lb = hex(substr($conv, 7, 1));
$H1 = $d0lb + $d0hb * 16;
$L1 = $d1lb * 256 + ($d1hb * 4096);
$H2 = ($d2lb * 65536) + ($d2hb * (65536 * 16));
$L2 = ($d3lb * (65536 * 256)) + ($d3hb * (65536 * 4096));
$Total = ($L1) + ($H1) + ($L2) + ($H2);
   print "TransmittedCTS              ",$Total;
    print " \n";
    
$UnicastReceivedPackets = substr($Data1,58,8);
$Total = "0";
$conv = $UnicastReceivedPackets;
$d0hb = hex(substr($conv, 0, 1));
$d0lb = hex(substr($conv, 1, 1));
$d1hb = hex(substr($conv, 2, 1));
$d1lb = hex(substr($conv, 3, 1));
$d2hb = hex(substr($conv, 4, 1));
$d2lb = hex(substr($conv, 5, 1));
$d3hb = hex(substr($conv, 6, 1));
$d3lb = hex(substr($conv, 7, 1));
$H1 = $d0lb + $d0hb * 16;
$L1 = $d1lb * 256 + ($d1hb * 4096);
$H2 = ($d2lb * 65536) + ($d2hb * (65536 * 16));
$L2 = ($d3lb * (65536 * 256)) + ($d3hb * (65536 * 4096));
$Total = ($L1) + ($H1) + ($L2) + ($H2);
    print "UnicastReceivedPackets      ",$Total;
    print " \n";
    
$BroadcastReceivedPackets = substr($Data1,66,8);
$Total = "0";
$conv = $BroadcastReceivedPackets;
$d0hb = hex(substr($conv, 0, 1));
$d0lb = hex(substr($conv, 1, 1));
$d1hb = hex(substr($conv, 2, 1));
$d1lb = hex(substr($conv, 3, 1));
$d2hb = hex(substr($conv, 4, 1));
$d2lb = hex(substr($conv, 5, 1));
$d3hb = hex(substr($conv, 6, 1));
$d3lb = hex(substr($conv, 7, 1));
$H1 = $d0lb + $d0hb * 16;
$L1 = $d1lb * 256 + ($d1hb * 4096);
$H2 = ($d2lb * 65536) + ($d2hb * (65536 * 16));
$L2 = ($d3lb * (65536 * 256)) + ($d3hb * (65536 * 4096));
$Total = ($L1) + ($H1) + ($L2) + ($H2);
    print "BroadcastReceivedPackets    ",$Total;
    print " \n";
    
$MulticastReceivedPackets = substr($Data1,74,8);
$Total = "0";
$conv = $MulticastReceivedPackets;
$d0hb = hex(substr($conv, 0, 1));
$d0lb = hex(substr($conv, 1, 1));
$d1hb = hex(substr($conv, 2, 1));
$d1lb = hex(substr($conv, 3, 1));
$d2hb = hex(substr($conv, 4, 1));
$d2lb = hex(substr($conv, 5, 1));
$d3hb = hex(substr($conv, 6, 1));
$d3lb = hex(substr($conv, 7, 1));
$H1 = $d0lb + $d0hb * 16;
$L1 = $d1lb * 256 + ($d1hb * 4096);
$H2 = ($d2lb * 65536) + ($d2hb * (65536 * 16));
$L2 = ($d3lb * (65536 * 256)) + ($d3hb * (65536 * 4096));
$Total = ($L1) + ($H1) + ($L2) + ($H2);
    print "MulticastReceivedPackets    ",$Total;
    print " \n";
    
$ReceivedBeacon = substr($Data1,82,8);
$Total = "0";
$conv = $ReceivedBeacon;
$d0hb = hex(substr($conv, 0, 1));
$d0lb = hex(substr($conv, 1, 1));
$d1hb = hex(substr($conv, 2, 1));
$d1lb = hex(substr($conv, 3, 1));
$d2hb = hex(substr($conv, 4, 1));
$d2lb = hex(substr($conv, 5, 1));
$d3hb = hex(substr($conv, 6, 1));
$d3lb = hex(substr($conv, 7, 1));
$H1 = $d0lb + $d0hb * 16;
$L1 = $d1lb * 256 + ($d1hb * 4096);
$H2 = ($d2lb * 65536) + ($d2hb * (65536 * 16));
$L2 = ($d3lb * (65536 * 256)) + ($d3hb * (65536 * 4096));
$Total = ($L1) + ($H1) + ($L2) + ($H2);
    print "ReceivedBeacon              ",$Total;
    print " \n";
    
$ReceivedACK = substr($Data1,90,8);
$Total = "0";
$conv = $ReceivedACK;
$d0hb = hex(substr($conv, 0, 1));
$d0lb = hex(substr($conv, 1, 1));
$d1hb = hex(substr($conv, 2, 1));
$d1lb = hex(substr($conv, 3, 1));
$d2hb = hex(substr($conv, 4, 1));
$d2lb = hex(substr($conv, 5, 1));
$d3hb = hex(substr($conv, 6, 1));
$d3lb = hex(substr($conv, 7, 1));
$H1 = $d0lb + $d0hb * 16;
$L1 = $d1lb * 256 + ($d1hb * 4096);
$H2 = ($d2lb * 65536) + ($d2hb * (65536 * 16));
$L2 = ($d3lb * (65536 * 256)) + ($d3hb * (65536 * 4096));
$Total = ($L1) + ($H1) + ($L2) + ($H2);
    print "ReceivedACK                 ",$Total;
    print " \n";
    
$ReceivedRTS = substr($Data1,98,8);
$Total = "0";
$conv = $ReceivedRTS;
$d0hb = hex(substr($conv, 0, 1));
$d0lb = hex(substr($conv, 1, 1));
$d1hb = hex(substr($conv, 2, 1));
$d1lb = hex(substr($conv, 3, 1));
$d2hb = hex(substr($conv, 4, 1));
$d2lb = hex(substr($conv, 5, 1));
$d3hb = hex(substr($conv, 6, 1));
$d3lb = hex(substr($conv, 7, 1));
$H1 = $d0lb + $d0hb * 16;
$L1 = $d1lb * 256 + ($d1hb * 4096);
$H2 = ($d2lb * 65536) + ($d2hb * (65536 * 16));
$L2 = ($d3lb * (65536 * 256)) + ($d3hb * (65536 * 4096));
$Total = ($L1) + ($H1) + ($L2) + ($H2);
    print "ReceivedRTS                 ",$Total;
   print " \n";
    
$ReceivedCTS = substr($Data1,106,8);
$Total = "0";
$conv = $ReceivedACK;
$d0hb = hex(substr($conv, 0, 1));
$d0lb = hex(substr($conv, 1, 1));
$d1hb = hex(substr($conv, 2, 1));
$d1lb = hex(substr($conv, 3, 1));
$d2hb = hex(substr($conv, 4, 1));
$d2lb = hex(substr($conv, 5, 1));
$d3hb = hex(substr($conv, 6, 1));
$d3lb = hex(substr($conv, 7, 1));
$H1 = $d0lb + $d0hb * 16;
$L1 = $d1lb * 256 + ($d1hb * 4096);
$H2 = ($d2lb * 65536) + ($d2hb * (65536 * 16));
$L2 = ($d3lb * (65536 * 256)) + ($d3hb * (65536 * 4096));
$Total = ($L1) + ($H1) + ($L2) + ($H2);
    print "ReceivedCTS                 ",$Total;
    print " \n";
    
$ACKFailure = substr($Data1,114,8);
$Total = "0";
$conv = $ACKFailure;
$d0hb = hex(substr($conv, 0, 1));
$d0lb = hex(substr($conv, 1, 1));
$d1hb = hex(substr($conv, 2, 1));
$d1lb = hex(substr($conv, 3, 1));
$d2hb = hex(substr($conv, 4, 1));
$d2lb = hex(substr($conv, 5, 1));
$d3hb = hex(substr($conv, 6, 1));
$d3lb = hex(substr($conv, 7, 1));
$H1 = $d0lb + $d0hb * 16;
$L1 = $d1lb * 256 + ($d1hb * 4096);
$H2 = ($d2lb * 65536) + ($d2hb * (65536 * 16));
$L2 = ($d3lb * (65536 * 256)) + ($d3hb * (65536 * 4096));
$Total = ($L1) + ($H1) + ($L2) + ($H2);
    print "ACKFailure                  ",$Total;
    print " \n";

$CTSFailure = substr($Data1,122,8);
$Total = "0";
$conv = $CTSFailure;
$d0hb = hex(substr($conv, 0, 1));
$d0lb = hex(substr($conv, 1, 1));
$d1hb = hex(substr($conv, 2, 1));
$d1lb = hex(substr($conv, 3, 1));
$d2hb = hex(substr($conv, 4, 1));
$d2lb = hex(substr($conv, 5, 1));
$d3hb = hex(substr($conv, 6, 1));
$d3lb = hex(substr($conv, 7, 1));
$H1 = $d0lb + $d0hb * 16;
$L1 = $d1lb * 256 + ($d1hb * 4096);
$H2 = ($d2lb * 65536) + ($d2hb * (65536 * 16));
$L2 = ($d3lb * (65536 * 256)) + ($d3hb * (65536 * 4096));
$Total = ($L1) + ($H1) + ($L2) + ($H2);
    print "CTSFailure                  ",$Total;
    print " \n";
    
$RetryPackets = substr($Data1,130,8);
$Total = "0";
$conv = $RetryPackets;
$d0hb = hex(substr($conv, 0, 1));
$d0lb = hex(substr($conv, 1, 1));
$d1hb = hex(substr($conv, 2, 1));
$d1lb = hex(substr($conv, 3, 1));
$d2hb = hex(substr($conv, 4, 1));
$d2lb = hex(substr($conv, 5, 1));
$d3hb = hex(substr($conv, 6, 1));
$d3lb = hex(substr($conv, 7, 1));
$H1 = $d0lb + $d0hb * 16;
$L1 = $d1lb * 256 + ($d1hb * 4096);
$H2 = ($d2lb * 65536) + ($d2hb * (65536 * 16));
$L2 = ($d3lb * (65536 * 256)) + ($d3hb * (65536 * 4096));
$Total = ($L1) + ($H1) + ($L2) + ($H2);
    print "RetryPackets                ",$Total;
    print " \n";
    
$ReceivedDuplicate = substr($Data1,138,8);
$Total = "0";
$conv = $RetryDuplicate;
$d0hb = hex(substr($conv, 0, 1));
$d0lb = hex(substr($conv, 1, 1));
$d1hb = hex(substr($conv, 2, 1));
$d1lb = hex(substr($conv, 3, 1));
$d2hb = hex(substr($conv, 4, 1));
$d2lb = hex(substr($conv, 5, 1));
$d3hb = hex(substr($conv, 6, 1));
$d3lb = hex(substr($conv, 7, 1));
$H1 = $d0lb + $d0hb * 16;
$L1 = $d1lb * 256 + ($d1hb * 4096);
$H2 = ($d2lb * 65536) + ($d2hb * (65536 * 16));
$L2 = ($d3lb * (65536 * 256)) + ($d3hb * (65536 * 4096));
$Total = ($L1) + ($H1) + ($L2) + ($H2);
    print "RetryDuplicate              ",$Total;
    print " \n";
    
$FailedPackets = substr($Data1,146,8);
$Total = "0";
$conv = $FailedPackets;
$d0hb = hex(substr($conv, 0, 1));
$d0lb = hex(substr($conv, 1, 1));
$d1hb = hex(substr($conv, 2, 1));
$d1lb = hex(substr($conv, 3, 1));
$d2hb = hex(substr($conv, 4, 1));
$d2lb = hex(substr($conv, 5, 1));
$d3hb = hex(substr($conv, 6, 1));
$d3lb = hex(substr($conv, 7, 1));
$H1 = $d0lb + $d0hb * 16;
$L1 = $d1lb * 256 + ($d1hb * 4096);
$H2 = ($d2lb * 65536) + ($d2hb * (65536 * 16));
$L2 = ($d3lb * (65536 * 256)) + ($d3hb * (65536 * 4096));
$Total = ($L1) + ($H1) + ($L2) + ($H2);
    print "FailedPackets               ",$Total;
    print " \n";
    
$AgedPackets = substr($Data1,154,8);
$Total = "0";
$conv = $AgedPackets;
$d0hb = hex(substr($conv, 0, 1));
$d0lb = hex(substr($conv, 1, 1));
$d1hb = hex(substr($conv, 2, 1));
$d1lb = hex(substr($conv, 3, 1));
$d2hb = hex(substr($conv, 4, 1));
$d2lb = hex(substr($conv, 5, 1));
$d3hb = hex(substr($conv, 6, 1));
$d3lb = hex(substr($conv, 7, 1));
$H1 = $d0lb + $d0hb * 16;
$L1 = $d1lb * 256 + ($d1hb * 4096);
$H2 = ($d2lb * 65536) + ($d2hb * (65536 * 16));
$L2 = ($d3lb * (65536 * 256)) + ($d3hb * (65536 * 4096));
$Total = ($L1) + ($H1) + ($L2) + ($H2);
    print "AgedPackets                 ",$Total;
    print " \n";
    
$FCSError = substr($Data1,162,8);
$Total = "0";
$conv = $FCSError;
$d0hb = hex(substr($conv, 0, 1));
$d0lb = hex(substr($conv, 1, 1));
$d1hb = hex(substr($conv, 2, 1));
$d1lb = hex(substr($conv, 3, 1));
$d2hb = hex(substr($conv, 4, 1));
$d2lb = hex(substr($conv, 5, 1));
$d3hb = hex(substr($conv, 6, 1));
$d3lb = hex(substr($conv, 7, 1));
$H1 = $d0lb + $d0hb * 16;
$L1 = $d1lb * 256 + ($d1hb * 4096);
$H2 = ($d2lb * 65536) + ($d2hb * (65536 * 16));
$L2 = ($d3lb * (65536 * 256)) + ($d3hb * (65536 * 4096));
$Total = ($L1) + ($H1) + ($L2) + ($H2);
    print "FCSError                    ",$Total;
    print " \n";
    
$InvalidPLCP = substr($Data1,170,8);
$Total = "0";
$conv = $InvalidPLCP;
$d0hb = hex(substr($conv, 0, 1));
$d0lb = hex(substr($conv, 1, 1));
$d1hb = hex(substr($conv, 2, 1));
$d1lb = hex(substr($conv, 3, 1));
$d2hb = hex(substr($conv, 4, 1));
$d2lb = hex(substr($conv, 5, 1));
$d3hb = hex(substr($conv, 6, 1));
$d3lb = hex(substr($conv, 7, 1));
$H1 = $d0lb + $d0hb * 16;
$L1 = $d1lb * 256 + ($d1hb * 4096);
$H2 = ($d2lb * 65536) + ($d2hb * (65536 * 16));
$L2 = ($d3lb * (65536 * 256)) + ($d3hb * (65536 * 4096));
$Total = ($L1) + ($H1) + ($L2) + ($H2);
    print "InvalidPLCP                 ",$Total;
    print " \n";
    print " \n";
    
# Break it down into the AT76C510MIB Lables for EthRX and EthTX Stats and print

#Data10 = RX Stats
#Data11 = TX Stats

print "Rx Ethernet Stats";
    print " \n";
    print " \n";

$TotalBytesRX = substr($Data10,2,8);
$Total = "0";
$conv = $TotalBytesRX;
$d0hb = hex(substr($conv, 0, 1));
$d0lb = hex(substr($conv, 1, 1));
$d1hb = hex(substr($conv, 2, 1));
$d1lb = hex(substr($conv, 3, 1));
$d2hb = hex(substr($conv, 4, 1));
$d2lb = hex(substr($conv, 5, 1));
$d3hb = hex(substr($conv, 6, 1));
$d3lb = hex(substr($conv, 7, 1));
$H1 = $d0lb + $d0hb * 16;
$L1 = $d1lb * 256 + ($d1hb * 4096);
$H2 = ($d2lb * 65536) + ($d2hb * (65536 * 16));
$L2 = ($d3lb * (65536 * 256)) + ($d3hb * (65536 * 4096));
$Total = ($L1) + ($H1) + ($L2) + ($H2);
    print "TotalBytesRX                ",$Total;
    print " \n";
    
$TotalPacketsRX = substr($Data10,10,8);
$Total = "0";
$conv = $TotalPacketsRX;
$d0hb = hex(substr($conv, 0, 1));
$d0lb = hex(substr($conv, 1, 1));
$d1hb = hex(substr($conv, 2, 1));
$d1lb = hex(substr($conv, 3, 1));
$d2hb = hex(substr($conv, 4, 1));
$d2lb = hex(substr($conv, 5, 1));
$d3hb = hex(substr($conv, 6, 1));
$d3lb = hex(substr($conv, 7, 1));
$H1 = $d0lb + $d0hb * 16;
$L1 = $d1lb * 256 + ($d1hb * 4096);
$H2 = ($d2lb * 65536) + ($d2hb * (65536 * 16));
$L2 = ($d3lb * (65536 * 256)) + ($d3hb * (65536 * 4096));
$Total = ($L1) + ($H1) + ($L2) + ($H2);
    print "TotalPacketsRX              ",$Total;
    print " \n";
    
$PacketCRCErrorRX = substr($Data10,18,8);
$Total = "0";
$conv = $PacketCRCErrorRX;
$d0hb = hex(substr($conv, 0, 1));
$d0lb = hex(substr($conv, 1, 1));
$d1hb = hex(substr($conv, 2, 1));
$d1lb = hex(substr($conv, 3, 1));
$d2hb = hex(substr($conv, 4, 1));
$d2lb = hex(substr($conv, 5, 1));
$d3hb = hex(substr($conv, 6, 1));
$d3lb = hex(substr($conv, 7, 1));
$H1 = $d0lb + $d0hb * 16;
$L1 = $d1lb * 256 + ($d1hb * 4096);
$H2 = ($d2lb * 65536) + ($d2hb * (65536 * 16));
$L2 = ($d3lb * (65536 * 256)) + ($d3hb * (65536 * 4096));
$Total = ($L1) + ($H1) + ($L2) + ($H2);
    print "PacketCRCErrorRX            ",$Total;
    print " \n";

$TotalJabberRX = substr($Data10,106,8);
$Total = "0";
$conv = $TotalJabberRX;
$d0hb = hex(substr($conv, 0, 1));
$d0lb = hex(substr($conv, 1, 1));
$d1hb = hex(substr($conv, 2, 1));
$d1lb = hex(substr($conv, 3, 1));
$d2hb = hex(substr($conv, 4, 1));
$d2lb = hex(substr($conv, 5, 1));
$d3hb = hex(substr($conv, 6, 1));
$d3lb = hex(substr($conv, 7, 1));
$H1 = $d0lb + $d0hb * 16;
$L1 = $d1lb * 256 + ($d1hb * 4096);
$H2 = ($d2lb * 65536) + ($d2hb * (65536 * 16));
$L2 = ($d3lb * (65536 * 256)) + ($d3hb * (65536 * 4096));
$Total = ($L1) + ($H1) + ($L2) + ($H2);
    print "TotalJabberRX               ",$Total;
    print " \n";
    print " \n";

print "Tx Ethernet Stats";
    print " \n";
    print " \n";
    
$TotalBytesTX = substr($Data11,2,8);
$Total = "0";
$conv = $TotalBytesTX;
$d0hb = hex(substr($conv, 0, 1));
$d0lb = hex(substr($conv, 1, 1));
$d1hb = hex(substr($conv, 2, 1));
$d1lb = hex(substr($conv, 3, 1));
$d2hb = hex(substr($conv, 4, 1));
$d2lb = hex(substr($conv, 5, 1));
$d3hb = hex(substr($conv, 6, 1));
$d3lb = hex(substr($conv, 7, 1));
$H1 = $d0lb + $d0hb * 16;
$L1 = $d1lb * 256 + ($d1hb * 4096);
$H2 = ($d2lb * 65536) + ($d2hb * (65536 * 16));
$L2 = ($d3lb * (65536 * 256)) + ($d3hb * (65536 * 4096));
$Total = ($L1) + ($H1) + ($L2) + ($H2);
    print "TotalBytesTX                ",$Total;
    print " \n";
    
$TotalPacketsTX = substr($Data11,10,8);
$Total = "0";
$conv = $TotalPacketsTX;
$d0hb = hex(substr($conv, 0, 1));
$d0lb = hex(substr($conv, 1, 1));
$d1hb = hex(substr($conv, 2, 1));
$d1lb = hex(substr($conv, 3, 1));
$d2hb = hex(substr($conv, 4, 1));
$d2lb = hex(substr($conv, 5, 1));
$d3hb = hex(substr($conv, 6, 1));
$d3lb = hex(substr($conv, 7, 1));
$H1 = $d0lb + $d0hb * 16;
$L1 = $d1lb * 256 + ($d1hb * 4096);
$H2 = ($d2lb * 65536) + ($d2hb * (65536 * 16));
$L2 = ($d3lb * (65536 * 256)) + ($d3hb * (65536 * 4096));
$Total = ($L1) + ($H1) + ($L2) + ($H2);
    print "TotalPacketsTX              ",$Total;
    print " \n";
    
$PacketCRCErrorTX = substr($Data11,18,8);
$Total = "0";
$conv = $PacketCRCErrorTX;
$d0hb = hex(substr($conv, 0, 1));
$d0lb = hex(substr($conv, 1, 1));
$d1hb = hex(substr($conv, 2, 1));
$d1lb = hex(substr($conv, 3, 1));
$d2hb = hex(substr($conv, 4, 1));
$d2lb = hex(substr($conv, 5, 1));
$d3hb = hex(substr($conv, 6, 1));
$d3lb = hex(substr($conv, 7, 1));
$H1 = $d0lb + $d0hb * 16;
$L1 = $d1lb * 256 + ($d1hb * 4096);
$H2 = ($d2lb * 65536) + ($d2hb * (65536 * 16));
$L2 = ($d3lb * (65536 * 256)) + ($d3hb * (65536 * 4096));
$Total = ($L1) + ($H1) + ($L2) + ($H2);
    print "PacketCRCErrorTX            ",$Total;
    print " \n";

$TotalCollisionsTX = substr($Data11,106,8);
$Total = "0";
$conv = $TotalCollisionsTX;
$d0hb = hex(substr($conv, 0, 1));
$d0lb = hex(substr($conv, 1, 1));
$d1hb = hex(substr($conv, 2, 1));
$d1lb = hex(substr($conv, 3, 1));
$d2hb = hex(substr($conv, 4, 1));
$d2lb = hex(substr($conv, 5, 1));
$d3hb = hex(substr($conv, 6, 1));
$d3lb = hex(substr($conv, 7, 1));
$H1 = $d0lb + $d0hb * 16;
$L1 = $d1lb * 256 + ($d1hb * 4096);
$H2 = ($d2lb * 65536) + ($d2hb * (65536 * 16));
$L2 = ($d3lb * (65536 * 256)) + ($d3hb * (65536 * 4096));
$Total = ($L1) + ($H1) + ($L2) + ($H2);
    print "TotalCollisionsTX           ",$Total;
    print " \n";
    print " \n";
    print "Operational IP Address      ",($Data20);
    print " \n";
    print "Operational IP Mask         ",($Data21);
    print " \n";
    print "Operational Ether Address   ",($Data22);
    print " \n";
    print "Operational Gateway         ",($Data23);
    print " \n";
    
$DHCPen = hex($Data24);
 
 if ($DHCPen == 1) {$Data24 = "Enabled";
  }
 if ($DHCPen == 2) {$Data24 = "Disabled";
  }
    print "Operational DHCP            ",($Data24);
    print " \n";
    
$PriPort = hex($Data25);
 
 if ($PriPort == 1) {$Data25 = "Ethernet";
  }
 if ($PriPort == 2) {$Data25 = "Wireless";
  }
    print "Operational Pri Port        ",($Data25);
    print " \n";
    
$ConfPort = hex($Data26);
 
 if ($ConfPort == 1) {$Data26 = "Ethernet";
  }
 if ($ConfPort == 2) {$Data26 = "Wireless";
  }
 if ($ConfPort == 3) {$Data26 = "Both";
  }
    print "Operational Config Port     ",($Data26);
    print " \n";

# All Done. Close.  
$session->close;
exit 0;


#The actual query control, depending on the type. 
sub snmpQuery() {
    my ($session, $result,$resultval,@values,$retval,@Rest,$query,$type);
    ($session,$query,$type) = @_;
    $result = $session->get_request(
				    -varbindlist => [$query]
				    );
#
# The error check is important, more so, if the values 
# returned is not correct. This messes up the logs!
#
    if (!defined($result)) {
#
# Ideally this should be handled by the MRTG properly. 
#	printf("ERROR: %s.\n", $session->error);
	$session->close;
# Though its wrong to return '0' as exit code for an error, we'd 
# do this so that MRTG behaves.
	return;
	exit 0;
    }

    $resultval = $result->{$query};
    if ( $type == 0 ) { 
	(@Rest) = split(" ",$resultval);
	($retval,@Rest) = reverse(@Rest);
    }
    if ( $type == 1 ) {
	@values = hexString($resultval);
	($retval,@Rest) = @values;
    } 
    if ( $type == 2 ) {
	@values = hexString($resultval);
	my ( $UTPax, $BTPax, $MTPax, $TBecon, $TACK, $TRTS, $TCTS, $URPax, $BRPax, $MRPax, @Rest) = @values;
	$retval = $UTPax + $BTPax + $MTPax;	
    }
    if ( $type == 3 ) {
	@values = hexString($resultval);
	my ( $UTPax, $BTPax, $MTPax, $TBecon, $TACK, $TRTS, $TCTS, $URPax, $BRPax, $MRPax, @Rest) = @values;
	$retval = $URPax + $BRPax + $MRPax;	
    }
    if ($type == 4 ){
	$retval = $resultval;
    }
    return $retval;
}



# For the case of the Hex-String, the string needs to be broken into
# the octets, and they are read in reverse. 
sub hexString() {
    my (@vals,$dList,@Rest,$length,$i);
    ($dList,@Rest) = @_;
    $length = length($dList);

# Sanitizing by removing the 0x character first. 
    $dList = substr($dList,2,$length);
    $length = $length - 2;
# Quick and dirty extraction of values.
    $i=0;
    while ($i<$length) {
	my $val = "";
	my $k = 6;
	do {
	    my $Temp = substr($dList,$i+$k,2);
	    $val = $val.$Temp;
	    $k = $k - 2;
	} while ($k >-1);
	$i = $i+8;
	push @vals, hex($val);
    }
    return @vals;
}

