ℹ️ Your data is safe here... unless you make the SNIP gods angry. And let's just say they have a really bad sense of humor.

From dGs-, 5 Years ago, written in PHP.
Embed
  1. <?php
  2. echo 'IEEE8021-Q-BRIDGE-MIB VLANs: ';
  3.  
  4. $vlanversion = snmp_get($device, 'dot1qVlanVersionNumber.0', '-Oqv', 'IEEE8021-Q-BRIDGE-MIB');
  5.  
  6. if ($vlanversion == 'version1' || $vlanversion == '2') {
  7.     echo "ver $vlanversion ";
  8.  
  9.     $vtpdomain_id = '1';
  10.     $vlans        = snmpwalk_cache_oid($device, 'dot1qVlanStaticName', array(), 'Q-BRIDGE-MIB');
  11.     $untag        = snmpwalk_cache_oid($device, 'dot1qVlanCurrentUntaggedPorts', array(), 'Q-BRIDGE-MIB', null, ['-OQUs', '--hexOutputLength=0']);
  12.     $tagoruntag   = snmpwalk_cache_oid($device, 'dot1qVlanCurrentEgressPorts', array(), 'Q-BRIDGE-MIB', null, ['-OQUs', '--hexOutputLength=0']);
  13.    
  14.     if ($tagoruntag == $null && $untag == $null) {
  15.         // if dot1qVlanCurrentTable doesn't exist then use the dot1qVlanStaticTable
  16.         $untaggedports     = 'dot1qVlanStaticUntaggedPorts';
  17.         $tagoruntagports   = 'dot1qVlanStaticEgressPorts';
  18.         $untag             = snmpwalk_cache_oid($device, $untaggedports, array(), 'Q-BRIDGE-MIB', null, ['-OQUs', '--hexOutputLength=0']);
  19.         $tagoruntag        = snmpwalk_cache_oid($device, $tagoruntagports, array(), 'Q-BRIDGE-MIB', null, ['-OQUs', '--hexOutputLength=0']);
  20.     } else {
  21.         $untaggedports     = 'dot1qVlanCurrentUntaggedPorts';
  22.         $tagoruntagports   = 'dot1qVlanCurrentEgressPorts';
  23.    
  24.         // drop dot1qVlanTimeMark, we don't care about it
  25.         $tagoruntag = array_reduce(array_keys($tagoruntag), function ($result, $key) use ($tagoruntag) {
  26.             list(, $new_key) = explode('.', $key);
  27.             $result[$new_key] = $tagoruntag[$key];
  28.             return $result;
  29.         }, []);
  30.         $untag = array_reduce(array_keys($untag), function ($result, $key) use ($untag) {
  31.             list(, $new_key) = explode('.', $key);
  32.             $result[$new_key] = $untag[$key];
  33.             return $result;
  34.         }, []);
  35.     }
  36.  
  37.     foreach ($vlans as $vlan_id => $vlan) {
  38.         d_echo(" $vlan_id");
  39.         if (is_array($vlans_db[$vtpdomain_id][$vlan_id])) {
  40.             $vlan_data = $vlans_db[$vtpdomain_id][$vlan_id];
  41.             if ($vlan_data['vlan_name'] != $vlan['dot1qVlanStaticName']) {
  42.                 $vlan_upd['vlan_name'] = $vlan['dot1qVlanStaticName'];
  43.                 dbUpdate($vlan_upd, 'vlans', '`vlan_id` = ?', array($vlan_data['vlan_id']));
  44.                 log_event("VLAN $vlan_id changed name {$vlan_data['vlan_name']} -> {$vlan['dot1qVlanStaticName']} ", $device, 'vlan', 3, $vlan_data['vlan_id']);
  45.                 echo 'U';
  46.             } else {
  47.                 echo '.';
  48.             }
  49.         } else {
  50.             dbInsert(array(
  51.                 'device_id' => $device['device_id'],
  52.                 'vlan_domain' => $vtpdomain_id,
  53.                 'vlan_vlan' => $vlan_id,
  54.                 'vlan_name' => $vlan['dot1qVlanStaticName'],
  55.                 'vlan_type' => array('NULL')
  56.             ), 'vlans');
  57.             echo '+';
  58.         }
  59.  
  60.         $device['vlans'][$vtpdomain_id][$vlan_id] = $vlan_id;
  61.  
  62.         $untagged_ids = q_bridge_bits2indices($untag[$vlan_id][$untaggedports]);
  63.         $egress_ids = q_bridge_bits2indices($tagoruntag[$vlan_id][$tagoruntagports]);
  64.  
  65.         foreach ($egress_ids as $port_id) {
  66.             if (isset($base_to_index[$port_id])) {
  67.                 $ifIndex = $base_to_index[$port_id];
  68.                 $per_vlan_data[$vlan_id][$ifIndex]['untagged'] = (in_array($port_id, $untagged_ids) ? 1 : 0);
  69.             }
  70.         }
  71.     }
  72. }
  73. echo PHP_EOL;
  74.  
captcha