Advertisement
d1cor

iproute_snmp.php

Dec 18th, 2012
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.49 KB | None | 0 0
  1. <pre>
  2. /*******************************************
  3. * Author     : Diego Cordoba / @d1cor      *
  4. * Contact    : d1cor.com.ar                *
  5. *******************************************/
  6. </pre>
  7. <?php
  8. $target_ip=$_GET['ip'];
  9. $community=$_GET['c'];
  10.  
  11. $result = snmprealwalk($target_ip,$community,'ipRoute');
  12.  
  13. foreach($result as $indice => $valor){
  14.         $variable=explode('::',$indice);
  15.         $valor_e=explode(': ',$valor);
  16.         $tmp1=explode('.',$variable[1]);
  17.         $dir_ip="$tmp1[1].$tmp1[2].$tmp1[3].$tmp1[4]";
  18.         if($tmp1[0]=='ipRouteIfIndex'){
  19.                 $ip_descr=snmpget($target_ip,$community,"ifDescr.$valor_e[1]");
  20.                 $ip_descr1=explode(': ',$ip_descr);
  21.                 $valor_e[1]=$ip_descr1[1];
  22.         }
  23.         if(($tmp1[0]=='ipRouteDest')&&($valor_e[1]=='0.0.0.0'))
  24.                 $valor_e[1]='default';
  25.  
  26.         $arreglo[$tmp1[0]][$dir_ip]=$valor_e[1];
  27. }
  28.  
  29. echo "<h2>Routing table via snmp</h2>";
  30.  
  31. echo "<table border=1>";
  32. echo "<tr><th>Destino</th>
  33.        <th>Gateway</th>
  34.        <th>Mascara</th>
  35.        <th>Tipo</th>
  36.        <th>Interfaz</th></tr>";
  37. foreach($arreglo['ipRouteDest'] as $indice => $valor ){
  38.         echo "<tr><td>".$arreglo['ipRouteDest'][$indice]."</td>";
  39.         echo "<td>".$arreglo['ipRouteNextHop'][$indice]."</td>";
  40.         echo "<td>".$arreglo['ipRouteMask'][$indice]."</td>";
  41.         echo "<td>".$arreglo['ipRouteType'][$indice]."</td>";
  42.         echo "<td>".$arreglo['ipRouteIfIndex'][$indice]."</td></tr>";
  43. }
  44.  
  45. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement