function get_enterasys_switch_ports($site, &$device, $lowPort = 0, $highPort = 0)
{
    global $debug, $scan_date;
    /* initialize port counters */
    $device["ports_total"] = 0;
    $device["ports_active"] = 0;
    $device["ports_trunk"] = 0;
    $device["vlans_total"] = 0;
    /* get VLAN information */
    $vlan_ids = xform_standard_indexed_data(".1.3.6.1.4.1.52.4.1.2.16.4.4.1.2", $device);
    /* get VLAN Trunk status */
    $vlan_trunkstatus = xform_standard_indexed_data(".1.3.6.1.4.1.52.4.1.2.16.3.1.1.5.4", $device);
    $device["vlans_total"] = sizeof($vlan_trunkstatus);
    mactrack_debug("VLAN data collected. There are " . sizeof($vlan_ids) . " VLANS.");
    /* get the ifIndexes for the device */
    $ifIndexes = xform_standard_indexed_data(".1.3.6.1.2.1.2.2.1.1", $device);
    mactrack_debug("ifIndexes data collection complete");
    /* get the ifTypes for the device */
    $ifTypes = xform_standard_indexed_data(".1.3.6.1.2.1.2.2.1.3", $device);
    mactrack_debug("ifTypes data collection complete.");
    /* get the ifNames for the device */
    $ifNames = xform_standard_indexed_data(".1.3.6.1.2.1.31.1.1.1.1", $device);
    mactrack_debug("ifNames data collection complete.");
    /* get ports that happen to be link ports */
    $link_ports = get_link_port_status($device);
    mactrack_debug("ipAddrTable scanning for link ports data collection complete.");
    if (sizeof($ifIndexes)) {
        foreach ($ifIndexes as $ifIndex) {
            $ifInterfaces[$ifIndex]["ifIndex"] = $ifIndex;
            $ifInterfaces[$ifIndex]["ifName"] = @$ifNames[$ifIndex];
            $ifInterfaces[$ifIndex]["ifType"] = mactrack_strip_alpha($ifTypes[$ifIndex]);
            $ifInterfaces[$ifIndex]["linkPort"] = @$link_ports[$ifIndex];
            $ifInterfaces[$ifIndex]["trunkPortState"] = @$vlan_trunkstatus[$ifIndex];
        }
    }
    mactrack_debug("ifInterfaces assembly complete.");
    /* calculate the number of end user ports */
    if (sizeof($ifTypes)) {
        foreach ($ifTypes as $ifType) {
            $ifType = mactrack_strip_alpha($ifType);
            if ($ifType >= 6 && $ifType <= 9) {
                $device["ports_total"]++;
            }
        }
    }
    mactrack_debug("Total Ports = " . $device["ports_total"]);
    /* calculate the number of trunk ports */
    if (sizeof($ifIndexes)) {
        foreach ($ifIndexes as $ifIndex) {
            if ($ifInterfaces[$ifIndex]["trunkPortState"] == 1) {
                $device["ports_trunk"]++;
            }
        }
    }
    mactrack_debug("Total Trunk Ports = " . $device["ports_trunk"]);
    /* get VLAN details */
    $i = 0;
    if (sizeof($vlan_ids)) {
        foreach ($vlan_ids as $vlan_id => $vlan_name) {
            $active_vlans[$i]["vlan_id"] = $vlan_id;
            $active_vlans[$i]["vlan_name"] = $vlan_name;
            $active_vlans++;
            $i++;
        }
    }
    if (sizeof($active_vlans)) {
        /* get the port status information */
        $port_results = get_base_dot1dTpFdbEntry_ports($site, $device, $ifInterfaces, "", "", FALSE);
        $port_vlan_data = xform_standard_indexed_data(".1.3.6.1.4.1.52.4.1.2.16.3.1.1.3.4", $device);
        $i = 0;
        $j = 0;
        $port_array = array();
        foreach ($port_results as $port_result) {
            mactrack_debug("Got Here");
            $ifIndex = $port_result["port_number"];
            $ifType = mactrack_strip_alpha($ifTypes[$ifIndex]);
            $ifName = $ifNames[$ifIndex];
            $portName = $ifName;
            $portTrunkStatus = @$ifInterfaces[$ifIndex]["trunkPortState"];
            /* only output legitimate end user ports */
            if ($ifType >= 6 && $ifType <= 9) {
                $port_array[$i]["vlan_id"] = @$port_vlan_data[$port_result["port_number"]];
                $port_array[$i]["vlan_name"] = @$vlan_ids[$port_array[$i]["vlan_id"]];
                $port_array[$i]["port_number"] = @$port_result["port_number"];
                $port_array[$i]["port_name"] = $portName;
                $port_array[$i]["mac_address"] = xform_mac_address($port_result["mac_address"]);
                $device["ports_active"]++;
                mactrack_debug("VLAN: " . $port_array[$i]["vlan_id"] . ", " . "NAME: " . $port_array[$i]["vlan_name"] . ", " . "PORT: " . $ifIndex . ", " . "NAME: " . $port_array[$i]["port_name"] . ", " . "MAC: " . $port_array[$i]["mac_address"]);
                $i++;
            }
            $j++;
        }
        /* display completion message */
        print "INFO: HOST: " . $device["hostname"] . ", TYPE: " . substr($device["snmp_sysDescr"], 0, 40) . ", TOTAL PORTS: " . $device["ports_total"] . ", ACTIVE PORTS: " . $device["ports_active"];
        $device["last_runmessage"] = "Data collection completed ok";
        $device["macs_active"] = sizeof($port_array);
        db_store_device_port_results($device, $port_array, $scan_date);
    } else {
        print "INFO: HOST: " . $device["hostname"] . ", TYPE: " . substr($device["snmp_sysDescr"], 0, 40) . ", No active devices on this network device.";
        $device["snmp_status"] = HOST_UP;
        $device["last_runmessage"] = "Data collection completed ok. No active devices on this network device.";
    }
    return $device;
}
function get_netscreen_arp_table($site, &$device)
{
    global $debug, $scan_date;
    /* get the atifIndexes for the device */
    $atifIndexes = xform_indexed_data(".1.3.6.1.2.1.3.1.1.1", $device, 6);
    if (sizeof($atifIndexes)) {
        $ifIntcount = 1;
    } else {
        $ifIntcount = 0;
    }
    if ($ifIntcount != 0) {
        $atifIndexes = xform_indexed_data(".1.3.6.1.2.1.4.22.1.1", $device, 5);
    }
    mactrack_debug("atifIndexes data collection complete");
    /* get the atPhysAddress for the device */
    if ($ifIntcount != 0) {
        $atPhysAddress = xform_indexed_data(".1.3.6.1.2.1.4.22.1.2", $device, 5);
    } else {
        $atPhysAddress = xform_indexed_data(".1.3.6.1.2.1.3.1.1.2", $device, 6);
    }
    /* convert the mac address if necessary */
    $keys = array_keys($atPhysAddress);
    $i = 0;
    if (sizeof($atPhysAddress)) {
        foreach ($atPhysAddress as $atAddress) {
            $atPhysAddress[$keys[$i]] = xform_mac_address($atAddress);
            $i++;
        }
    }
    mactrack_debug("atPhysAddress data collection complete");
    /* get the atPhysAddress for the device */
    if ($ifIntcount != 0) {
        $atNetAddress = xform_indexed_data(".1.3.6.1.2.1.4.22.1.3", $device, 5);
    } else {
        $atNetAddress = xform_indexed_data(".1.3.6.1.2.1.3.1.1.3", $device, 6);
    }
    mactrack_debug("atNetAddress data collection complete");
    /* get the ifNames for the device */
    $keys = array_keys($atifIndexes);
    $i = 0;
    if (sizeof($atifIndexes)) {
        foreach ($atifIndexes as $atifIndex) {
            $atEntries[$i]["atifIndex"] = $atifIndex;
            $atEntries[$i]["atPhysAddress"] = $atPhysAddress[$keys[$i]];
            $atEntries[$i]["atNetAddress"] = xform_net_address($atNetAddress[$keys[$i]]);
            $i++;
        }
    }
    mactrack_debug("atEntries assembly complete.");
    /* output details to database */
    if (sizeof($atEntries)) {
        foreach ($atEntries as $atEntry) {
            $insert_string = "REPLACE INTO mac_track_ips " . "(site_id,device_id,hostname,device_name,port_number," . "mac_address,ip_address,scan_date)" . " VALUES ('" . $device["site_id"] . "','" . $device["device_id"] . "','" . $device["hostname"] . "','" . $device["device_name"] . "','" . $atEntry["atifIndex"] . "','" . $atEntry["atPhysAddress"] . "','" . $atEntry["atNetAddress"] . "','" . $scan_date . "')";
            //		mactrack_debug("SQL: " . $insert_string);
            db_execute($insert_string);
        }
    }
    /* save ip information for the device */
    $device["ips_total"] = sizeof($atEntries);
    db_execute("UPDATE mac_track_devices SET ips_total ='" . $device["ips_total"] . "' WHERE device_id='" . $device["device_id"] . "'");
    mactrack_debug("HOST: " . $device["hostname"] . ", IP address information collection complete");
}
Example #3
0
function get_3Com_base_dot1dTpFdbEntry_ports($site, &$device, &$ifInterfaces, $snmp_readstring = "", $store_to_db = TRUE, $lowPort = 1, $highPort = 9999)
{
    global $debug, $scan_date;
    /* initialize variables */
    $port_keys = array();
    $return_array = array();
    $new_port_key_array = array();
    $port_key_array = array();
    $port_descr = array();
    $port_number = 0;
    $ports_active = 0;
    $active_ports = 0;
    $ports_total = 0;
    /* cisco uses a hybrid read string, if one is not defined, use the default */
    if ($snmp_readstring == "") {
        $snmp_readstring = $device["snmp_readstring"];
    }
    /* get the operational status of the ports */
    $active_ports_array = xform_standard_indexed_data(".1.3.6.1.2.1.2.2.1.8", $device);
    $indexes = array_keys($active_ports_array);
    $i = 0;
    foreach ($active_ports_array as $port_info) {
        if ($ifInterfaces[$indexes[$i]]["ifType"] >= 6 && $ifInterfaces[$indexes[$i]]["ifType"] <= 9 || $ifInterfaces[$indexes[$i]]["ifType"] == 117) {
            if ($port_info == 1) {
                $ports_active++;
            }
            $ports_total++;
        }
        $i++;
    }
    if ($store_to_db) {
        print "INFO: HOST: " . $device["hostname"] . ", TYPE: " . substr($device["snmp_sysDescr"], 0, 40) . ", TOTAL PORTS: " . $ports_total . ", OPER PORTS: " . $ports_active;
        if ($debug) {
            print "\n";
        }
        $device["ports_active"] = $ports_active;
        $device["ports_total"] = $ports_total;
        $device["macs_active"] = 0;
    }
    if ($ports_active > 0) {
        /* get bridge port to ifIndex mapping */
        $bridgePortIfIndexes = xform_standard_indexed_data(".1.3.6.1.2.1.17.1.4.1.2", $device, $snmp_readstring);
        $port_status = xform_stripped_oid(".1.3.6.1.2.1.17.4.3.1.3", $device, $snmp_readstring);
        /* get device active port numbers */
        $port_numbers = xform_stripped_oid(".1.3.6.1.2.1.17.4.3.1.2", $device, $snmp_readstring);
        /* get the ignore ports list from device */
        $ignore_ports = port_list_to_array($device["ignorePorts"]);
        /* determine user ports for this device and transfer user ports to
        		   a new array.
        		*/
        $i = 0;
        foreach ($port_numbers as $key => $port_number) {
            if ($highPort == 0 || $port_number >= $lowPort && $port_number <= $highPort) {
                $ifname = $ifInterfaces[$bridgePortIfIndexes[$port_number]]["ifName"];
                if (!in_array($ifname, $ignore_ports)) {
                    if (@$port_status[$key] == "3") {
                        $port_key_array[$i]["key"] = $key;
                        $port_key_array[$i]["port_number"] = $port_number;
                        $i++;
                    }
                }
            }
        }
        /* compare the user ports to the brige port data, store additional
        		   relevant data about the port.
        		*/
        $i = 0;
        foreach ($port_key_array as $port_key) {
            /* map bridge port to interface port and check type */
            if ($port_key["port_number"] > 0) {
                if (sizeof($bridgePortIfIndexes) != 0) {
                    /* some hubs do not always return a port number in the bridge table.
                    			   test for it by isset and substiture the port number from the ifTable
                    			   if it isnt in the bridge table
                    			*/
                    if (isset($bridgePortIfIndexes[$port_key["port_number"]])) {
                        $brPortIfIndex = @$bridgePortIfIndexes[$port_key["port_number"]];
                    } else {
                        $brPortIfIndex = @$port_key["port_number"];
                    }
                    $brPortIfType = @$ifInterfaces[$brPortIfIndex]["ifType"];
                } else {
                    $brPortIfIndex = $port_key["port_number"];
                    $brPortIfType = @$ifInterfaces[$port_key["port_number"]]["ifType"];
                }
                if (($brPortIfType >= 6 && $brPortIfType <= 9 || $brPortIfType == 117) && !isset($ifInterfaces[$brPortIfIndex]["portLink"])) {
                    /* set some defaults  */
                    $new_port_key_array[$i]["vlan_id"] = "N/A";
                    $new_port_key_array[$i]["vlan_name"] = "N/A";
                    $new_port_key_array[$i]["mac_address"] = "NOT USER";
                    $new_port_key_array[$i]["port_number"] = "NOT USER";
                    $new_port_key_array[$i]["port_name"] = "N/A";
                    /* now set the real data */
                    $new_port_key_array[$i]["key"] = $port_key["key"];
                    $new_port_key_array[$i]["port_number"] = $port_key["port_number"];
                    $new_port_key_array[$i]["port_name"] = $ifInterfaces[$brPortIfIndex]["ifName"];
                    $i++;
                }
            }
        }
        mactrack_debug("Port number information collected.");
        /* map mac address */
        /* only continue if there were user ports defined */
        if (sizeof($new_port_key_array) > 0) {
            /* get the bridges active MAC addresses */
            $port_macs = xform_stripped_oid(".1.3.6.1.2.1.17.4.3.1.1", $device, $snmp_readstring);
            foreach ($port_macs as $key => $port_mac) {
                $port_macs[$key] = xform_mac_address($port_mac);
            }
            foreach ($new_port_key_array as $key => $port_key) {
                $new_port_key_array[$key]["mac_address"] = @$port_macs[$port_key["key"]];
                mactrack_debug("INDEX: '" . $key . "' MAC ADDRESS: " . $new_port_key_array[$key]["mac_address"]);
            }
            mactrack_debug("Port mac address information collected.");
        } else {
            mactrack_debug("No user ports on this network.");
        }
    } else {
        mactrack_debug("No user ports on this network.");
    }
    if ($store_to_db) {
        if ($ports_active <= 0) {
            $device["last_runmessage"] = "Data collection completed ok";
        } elseif (sizeof($new_port_key_array) > 0) {
            $device["last_runmessage"] = "Data collection completed ok";
            $device["macs_active"] = sizeof($new_port_key_array);
            db_store_device_port_results($device, $new_port_key_array, $scan_date);
        } else {
            $device["last_runmessage"] = "WARNING: Poller did not find active ports on this device.";
        }
        if (!$debug) {
            print " - Complete\n";
        }
    } else {
        return $new_port_key_array;
    }
}
Example #4
0
function get_IOS_dot1dTpFdbEntry_ports($site, &$device, $lowPort = 0, $highPort = 0)
{
    global $debug, $scan_date;
    /* initialize port counters */
    $device["ports_total"] = 0;
    $device["ports_active"] = 0;
    $device["ports_trunk"] = 0;
    $device["vlans_total"] = 0;
    /* Variables to determine VLAN information */
    $vlan_ids = xform_standard_indexed_data(".1.3.6.1.4.1.9.9.46.1.3.1.1.2", $device);
    $vlan_names = xform_standard_indexed_data(".1.3.6.1.4.1.9.9.46.1.3.1.1.4", $device);
    $vlan_trunkstatus = xform_standard_indexed_data(".1.3.6.1.4.1.9.9.46.1.6.1.1.14", $device);
    $device["vlans_total"] = sizeof($vlan_ids) - 3;
    mactrack_debug("There are " . (sizeof($vlan_ids) - 3) . " VLANS.");
    /* get the ifIndexes for the device */
    $ifIndexes = xform_standard_indexed_data(".1.3.6.1.2.1.2.2.1.1", $device);
    mactrack_debug("ifIndexes data collection complete");
    $ifInterfaces = build_InterfacesTable($device, $ifIndexes, TRUE, TRUE);
    /* get the Voice VLAN information if it exists */
    $portVoiceVLANs = xform_standard_indexed_data(".1.3.6.1.4.1.9.9.87.1.4.1.1.37.0", $device);
    if (sizeof($portVoiceVLANs) > 0) {
        $vvlans = TRUE;
    } else {
        $portVoiceVLANs = xform_standard_indexed_data(".1.3.6.1.4.1.9.9.68.1.5.1.1.1", $device);
        if (sizeof($portVoiceVLANs) > 0) {
            $vvlans = TRUE;
        } else {
            $vvlans = FALSE;
        }
    }
    mactrack_debug("Cisco Voice VLAN collection complete");
    if ($vvlans) {
        mactrack_debug("Voice VLANs exist on this device");
    } else {
        mactrack_debug("Voice VLANs do not exist on this device");
    }
    if (sizeof($ifIndexes)) {
        foreach ($ifIndexes as $ifIndex) {
            $ifInterfaces[$ifIndex]["trunkPortState"] = @$vlan_trunkstatus[$ifIndex];
            if ($vvlans) {
                $ifInterfaces[$ifIndex]["vVlanID"] = @$portVoiceVLANs[$ifIndex];
            }
            if ($ifInterfaces[$ifIndex]["ifType"] == 6) {
                $device["ports_total"]++;
            }
            if ($ifInterfaces[$ifIndex]["trunkPortState"] == "1") {
                $device["ports_trunk"]++;
            }
        }
    }
    mactrack_debug("ifInterfaces assembly complete.");
    /* build VLAN array from results */
    $i = 0;
    $j = 0;
    $active_vlans = array();
    if (sizeof($vlan_ids)) {
        foreach ($vlan_ids as $vlan_number => $vlanStatus) {
            $vlanName = $vlan_names[$vlan_number];
            if ($vlanStatus == 1) {
                /* vlan is operatinal */
                switch ($vlan_number) {
                    case "1002":
                    case "1003":
                    case "1004":
                    case "1005":
                        $active_vlan_ports = 0;
                        break;
                    default:
                        if ($device["snmp_version"] < "3") {
                            $snmp_readstring = $device["snmp_readstring"] . "@" . $vlan_number;
                            $active_vlan_ports = cacti_snmp_get($device["hostname"], $snmp_readstring, ".1.3.6.1.2.1.17.1.2.0", $device["snmp_version"], $device["snmp_username"], $device["snmp_password"], $device["snmp_auth_protocol"], $device["snmp_priv_passphrase"], $device["snmp_priv_protocol"], $device["snmp_context"], $device["snmp_port"], $device["snmp_timeout"], $device["snmp_retries"]);
                        } else {
                            $active_vlan_ports = cacti_snmp_get($device["hostname"], $snmp_readstring, ".1.3.6.1.2.1.17.1.2.0", $device["snmp_version"], $device["snmp_username"], $device["snmp_password"], $device["snmp_auth_protocol"], $device["snmp_priv_passphrase"], $device["snmp_priv_protocol"], $vlan_number, $device["snmp_port"], $device["snmp_timeout"], $device["snmp_retries"]);
                        }
                        if (!is_numeric($active_vlan_ports) || $active_vlan_ports < 0) {
                            $active_vlan_ports = 0;
                        }
                        mactrack_debug("VLAN Analysis for VLAN: " . $vlan_number . "/" . $vlanName . " is complete. ACTIVE PORTS: " . $active_vlan_ports);
                        if ($active_vlan_ports > 0) {
                            /* does the vlan have active ports on it */
                            $active_vlans[$j]["vlan_id"] = $vlan_number;
                            $active_vlans[$j]["vlan_name"] = $vlanName;
                            $active_vlans[$j]["active_ports"] = $active_vlan_ports;
                            $active_vlans++;
                            $j++;
                        }
                }
            }
            $i++;
        }
    }
    if (sizeof($active_vlans)) {
        $i = 0;
        /* get the port status information */
        foreach ($active_vlans as $active_vlan) {
            if ($device["snmp_version"] < "3") {
                $snmp_readstring = $device["snmp_readstring"] . "@" . $active_vlan["vlan_id"];
            } else {
                $snmp_readstring = "cisco@" . $active_vlan["vlan_id"];
            }
            mactrack_debug("Processing has begun for VLAN: " . $active_vlan["vlan_id"]);
            if ($highPort == 0) {
                $active_vlans[$i]["port_results"] = get_base_dot1dTpFdbEntry_ports($site, $device, $ifInterfaces, $snmp_readstring, FALSE);
            } else {
                $active_vlans[$i]["port_results"] = get_base_dot1dTpFdbEntry_ports($site, $device, $ifInterfaces, $snmp_readstring, FALSE, $lowPort, $highPort);
            }
            /* get bridge port mappings */
            /* get bridge port to ifIndex mappings */
            mactrack_debug("Bridge port information about to be collected.");
            mactrack_debug("VLAN_ID: " . $active_vlans[$i]["vlan_id"] . ", VLAN_NAME: " . $active_vlans[$i]["vlan_name"] . ", ACTIVE PORTS: " . sizeof($active_vlans[$i]["port_results"]));
            if (sizeof($active_vlans[$i]["port_results"]) > 0) {
                $brPorttoifIndexes[$i] = xform_standard_indexed_data(".1.3.6.1.2.1.17.1.4.1.2", $device, $snmp_readstring);
                mactrack_debug("Bridge port information collection complete.");
            }
            $i++;
        }
        $i = 0;
        $j = 0;
        $port_array = array();
        mactrack_debug("Final cross check's now being performed.");
        if (sizeof($active_vlans)) {
            foreach ($active_vlans as $active_vlan) {
                if (sizeof($active_vlan["port_results"])) {
                    foreach ($active_vlan["port_results"] as $port_result) {
                        $ifIndex = @$brPorttoifIndexes[$j][$port_result["port_number"]];
                        $ifType = @$ifInterfaces[$ifIndex]["ifType"];
                        $portNumber = @$ifInterfaces[$ifIndex]["ifName"];
                        $portName = @$ifInterfaces[$ifIndex]["ifAlias"];
                        $portTrunk = @$portTrunking[$ifName];
                        if ($vvlans) {
                            $vVlanID = @$portVoiceVLANs[$ifIndex];
                        } else {
                            $vVlanID = -1;
                        }
                        $portTrunkStatus = @$ifInterfaces[$ifIndex]["trunkPortState"];
                        /* only output legitamate end user ports */
                        if ($ifType == 6) {
                            if ($portTrunkStatus == "2" || empty($portTrunkStatus) || $vVlanID > 0 && $vVlanID <= 1000) {
                                $port_array[$i]["vlan_id"] = $active_vlan["vlan_id"];
                                $port_array[$i]["vlan_name"] = $active_vlan["vlan_name"];
                                $port_array[$i]["port_number"] = $portNumber;
                                $port_array[$i]["port_name"] = $portName;
                                $port_array[$i]["mac_address"] = xform_mac_address($port_result["mac_address"]);
                                $device["ports_active"]++;
                                $i++;
                                mactrack_debug("VLAN: " . $active_vlan["vlan_id"] . ", " . "NAME: " . $active_vlan["vlan_name"] . ", " . "PORT: " . $portNumber . ", " . "NAME: " . $portName . ", " . "MAC: " . $port_result["mac_address"]);
                            }
                        }
                    }
                }
                $j++;
            }
        }
        /* display completion message */
        print "\nINFO: HOST: " . $device["hostname"] . ", TYPE: " . substr($device["snmp_sysDescr"], 0, 40) . ", TOTAL PORTS: " . $device["ports_total"] . ", ACTIVE PORTS: " . $device["ports_active"] . "\n";
        $device["last_runmessage"] = "Data collection completed ok";
        $device["macs_active"] = sizeof($port_array);
        db_store_device_port_results($device, $port_array, $scan_date);
    } else {
        print "\nINFO: HOST: " . $device["hostname"] . ", TYPE: " . substr($device["snmp_sysDescr"], 0, 40) . ", No active end devices on this device.\n";
        $device["snmp_status"] = HOST_UP;
        $device["last_runmessage"] = "Data collection completed ok.  No active end devices on this device.";
    }
    return $device;
}
Example #5
0
function get_JEX_switch_ports($site, &$device, $lowPort = 0, $highPort = 0)
{
    global $debug, $scan_date;
    /* initialize port counters */
    $device["ports_total"] = 0;
    $device["ports_active"] = 0;
    $device["ports_trunk"] = 0;
    /* get VLAN information */
    $vlan_ids = xform_standard_indexed_data(".1.3.6.1.4.1.2636.3.40.1.5.1.5.1.5", $device);
    $vlan_names = xform_standard_indexed_data(".1.3.6.1.4.1.2636.3.40.1.5.1.5.1.2", $device);
    /* get VLAN Trunk status */
    $device["vlans_total"] = sizeof($vlan_ids) - 1;
    mactrack_debug("VLAN data collected. There are " . (sizeof($vlan_ids) - 1) . " VLANS.");
    /* get the ifIndexes for the device */
    $ifIndexes = xform_standard_indexed_data(".1.3.6.1.2.1.2.2.1.1", $device);
    mactrack_debug("ifIndexes data collection complete");
    /* get and store the interfaces table */
    $ifInterfaces = build_InterfacesTable($device, $ifIndexes, TRUE, FALSE);
    foreach ($ifIndexes as $ifIndex) {
        $ifInterfaces[$ifIndex]["trunkPortState"] = @$vlan_trunkstatus[$ifIndex];
        if ($ifInterfaces[$ifIndex]["ifType"] == "propVirtual(53)" or $ifInterfaces[$ifIndex]["ifType"] == "ieee8023adLag(161)") {
            $device["ports_total"]++;
        }
        if ($ifInterfaces[$ifIndex]["trunkPortState"] == 3) {
            $device["ports_trunk"]++;
        }
    }
    mactrack_debug("ifInterfaces assembly complete.");
    $i = 0;
    foreach ($vlan_ids as $vlan_id => $vlan_num) {
        $active_vlans[$vlan_id]["vlan_id"] = $vlan_num;
        $active_vlans[$vlan_id]["vlan_name"] = $vlan_names[$vlan_id];
        $active_vlans++;
        $i++;
    }
    mactrack_debug("Vlan assembly complete.");
    if (sizeof($active_vlans) > 0) {
        $i = 0;
        /* get the port status information */
        //$port_results = get_base_dot1dTpFdbEntry_ports($site, $device, $ifInterfaces, "", "", FALSE);
        $mac_results = xform_stripped_oid(".1.3.6.1.2.1.17.7.1.2.2.1.2", $device);
        $port_results = xform_stripped_oid(".1.3.6.1.2.1.17.1.4.1.2", $device);
        $i = 0;
        $j = 0;
        $port_array = array();
        foreach ($mac_results as $num => $mac_result) {
            if ($mac_result != 0) {
                $Xvlanid = substr($num, 0, strpos($num, "."));
                $Xmac = mach(substr($num, strpos($num, ".") + 1));
                $ifIndex = $port_results[$mac_result];
                $ifType = $ifInterfaces[$ifIndex]["ifType"];
                $ifName = $ifInterfaces[$ifIndex]["ifName"];
                $portName = $ifName;
                $portTrunkStatus = @$ifInterfaces[$ifIndex]["trunkPortState"];
                /* only output legitamate end user ports */
                //if ((($ifType >= 6) && ($ifType <= 9)) and ( $portName != "" or $portName != "1" )) {
                if ($portName != "" and $portName != "1") {
                    $port_array[$i]["vlan_id"] = $active_vlans[$Xvlanid]["vlan_id"];
                    //@$vlan_ids[$Xvlanid];
                    $port_array[$i]["vlan_name"] = $active_vlans[$Xvlanid]["vlan_name"];
                    //@$vlan_names[$Xvlandid];
                    $port_array[$i]["port_number"] = @$port_results[$mac_result];
                    $port_array[$i]["port_name"] = trim($ifName);
                    $port_array[$i]["mac_address"] = xform_mac_address($Xmac);
                    $device["ports_active"]++;
                    mactrack_debug("VLAN: " . $port_array[$i]["vlan_id"] . ", " . "NAME: " . $port_array[$i]["vlan_name"] . ", " . "PORT: " . $ifIndex . ", " . "NAME: " . $port_array[$i]["port_name"] . ", " . "MAC: " . $port_array[$i]["mac_address"]);
                    $i++;
                }
                $j++;
            }
        }
        /* display completion message */
        print "INFO: HOST: " . $device["hostname"] . ", TYPE: " . substr($device["snmp_sysDescr"], 0, 40) . ", TOTAL PORTS: " . $device["ports_total"] . ", ACTIVE PORTS: " . $device["ports_active"];
        $device["last_runmessage"] = "Data collection completed ok";
        $device["macs_active"] = sizeof($port_array);
        db_store_device_port_results($device, $port_array, $scan_date);
    } else {
        print "INFO: HOST: " . $device["hostname"] . ", TYPE: " . substr($device["snmp_sysDescr"], 0, 40) . ", No active devcies on this network device.";
        $device["snmp_status"] = HOST_UP;
        $device["last_runmessage"] = "Data collection completed ok. No active devices on this network device.";
    }
    return $device;
}
function get_CTAlias_table($site, &$device)
{
    global $debug, $scan_date;
    mactrack_debug("FUNCTION: get_CTAlias_table started");
    /* get the CTAlias Table for the device */
    $CTAliasInterfaces = xform_indexed_data(".1.3.6.1.4.1.52.4.1.3.7.1.1.1.1.3", $device, 2);
    mactrack_debug("CTAliasInterfaces data collection complete: " . sizeof($CTAliasInterfaces));
    /* get the CTAliasMacAddress for the device */
    $CTAliasMacAddress = xform_indexed_data(".1.3.6.1.4.1.52.4.1.3.7.1.1.1.1.4", $device, 2);
    mactrack_debug("CTAliasMacAddress data collection complete: " . sizeof($CTAliasMacAddress));
    /* convert the mac address if necessary */
    $keys = array_keys($CTAliasMacAddress);
    $i = 0;
    foreach ($CTAliasMacAddress as $MacAddress) {
        $CTAliasMacAddress[$keys[$i]] = xform_mac_address($MacAddress);
        $i++;
    }
    /* get the CTAliasProtocol Table for the device */
    $CTAliasProtocol = xform_indexed_data(".1.3.6.1.4.1.52.4.1.3.7.1.1.1.1.6", $device, 2);
    mactrack_debug("CTAliasProtocol data collection complete: " . sizeof($CTAliasProtocol));
    /* get the CTAliasAddressText for the device */
    $CTAliasAddressText = xform_indexed_data(".1.3.6.1.4.1.52.4.1.3.7.1.1.1.1.9", $device, 2);
    mactrack_debug("CTAliasAddressText data collection complete: " . sizeof($CTAliasAddressText));
    /* get the ifNames for the device */
    $keys = array_keys($CTAliasInterfaces);
    $i = 0;
    $CTAliasEntries = array();
    foreach ($CTAliasInterfaces as $ifIndex) {
        $CTAliasEntries[$i]["ifIndex"] = $ifIndex;
        #		$CTAliasEntries[$i]["timestamp"] = @substr($keys[$i], 0, stripos($keys[$i], '.'));
        $CTAliasEntries[$i]["timestamp"] = $keys[$i];
        $CTAliasEntries[$i]["CTAliasProtocol"] = @$CTAliasProtocol[$keys[$i]];
        $CTAliasEntries[$i]["CTAliasMacAddress"] = @$CTAliasMacAddress[$keys[$i]];
        #		$CTAliasEntries[$i]["CTAliasAddressText"] = @xform_net_address($CTAliasAddressText[$keys[$i]]);
        $CTAliasEntries[$i]["CTAliasAddressText"] = @$CTAliasAddressText[$keys[$i]];
        $i++;
    }
    mactrack_debug("CTAliasEntries assembly complete: " . sizeof($CTAliasEntries));
    /* output details to database */
    if (count($CTAliasEntries) > 0) {
        foreach ($CTAliasEntries as $CTAliasEntry) {
            /* drop non-IP protocols */
            if ($CTAliasEntry["CTAliasProtocol"] != 1) {
                continue;
            }
            $insert_string = "REPLACE INTO mac_track_ips " . "(site_id,device_id,hostname,device_name,port_number," . "mac_address,ip_address,scan_date)" . " VALUES ('" . $device["site_id"] . "','" . $device["device_id"] . "','" . $device["hostname"] . "'," . db_qstr($device["device_name"]) . ",'" . $CTAliasEntry["ifIndex"] . "','" . $CTAliasEntry["CTAliasMacAddress"] . "','" . $CTAliasEntry["CTAliasAddressText"] . "','" . $scan_date . "')";
            #			mactrack_debug("SQL: " . $insert_string);
            db_execute($insert_string);
        }
    }
    /* save ip information for the device */
    $device["ips_total"] = sizeof($CTAliasEntries);
    db_execute("UPDATE mac_track_devices SET ips_total ='" . $device["ips_total"] . "' WHERE device_id='" . $device["device_id"] . "'");
    mactrack_debug("HOST: " . $device["hostname"] . ", IP address information collection complete: " . $device["ips_total"]);
}
function get_extreme_arp_table($site, &$device, $extremeware = false)
{
    global $debug, $scan_date;
    /*
    EXTREME-FDB-MIB::extremeFdbIpFdbIPAddress : The IP Address of the IP FDB entry.
    .1.3.6.1.4.1.1916.1.16.2.1.2
    EXTREME-FDB-MIB::extremeFdbIpFdbMacAddress : The MAC address corresponding to the IP Address.
    .1.3.6.1.4.1.1916.1.16.2.1.3
    EXTREME-FDB-MIB::extremeFdbIpFdbVlanIfIndex : The ifIndex of the Vlan on which this ip is learned.
    .1.3.6.1.4.1.1916.1.16.2.1.4
    EXTREME-FDB-MIB::extremeFdbIpFdbPortIfIndex : The IfIndex of the port on which this entry was learned.
    .1.3.6.1.4.1.1916.1.16.2.1.5
    EXTREME-VLAN-MIB::extremeVlanIfIndex.<vlanid> = index
    .1.3.6.1.4.1.1916.1.2.1.2.1.1
    EXTREME-VLAN-MIB::extremeVlanIfDescr.<vlanid> = description
    .1.3.6.1.4.1.1916.1.2.1.2.1.2
    EXTREME-VLAN-MIB::extremeVlanIfVlanId.<vlanid> = tag id
    .1.3.6.1.4.1.1916.1.2.1.2.1.10
    BRIDGE-MIB::dot1dBasePortIfIndex : get Ifindex from extremeFdbIpFdbPortIfIndex
    .1.3.6.1.2.1.17.1.4.1.2
    IF-MIB::ifName : get name of port from IfIndex
    .1.3.6.1.2.1.31.1.1.1.1
    */
    if ($extremeware) {
        // for extremeware use standard apr table + ifDescr for interface name
        /* get the atifIndexes for the device */
        $atifIndexes = xform_stripped_oid(".1.3.6.1.2.1.3.1.1.1", $device);
        $atEntries = array();
        if (sizeof($atifIndexes)) {
            mactrack_debug("atifIndexes data collection complete");
            $atPhysAddress = xform_stripped_oid(".1.3.6.1.2.1.3.1.1.2", $device);
            mactrack_debug("atPhysAddress data collection complete");
            $atNetAddress = xform_stripped_oid(".1.3.6.1.2.1.3.1.1.3", $device);
            mactrack_debug("atNetAddress data collection complete");
            $ifDescr = xform_stripped_oid(".1.3.6.1.2.1.2.2.1.2", $device);
            mactrack_debug("ifDescr data collection complete");
        }
        $i = 0;
        if (sizeof($atifIndexes)) {
            foreach ($atifIndexes as $key => $atifIndex) {
                $atEntries[$i]["atifIndex"] = $ifDescr[$atifIndex];
                $atEntries[$i]["atPhysAddress"] = xform_mac_address($atPhysAddress[$key]);
                $atEntries[$i]["atNetAddress"] = xform_net_address($atNetAddress[$key]);
                $i++;
            }
        }
    } else {
        /* get the atifIndexes for the device */
        $FdbPortIfIndex = xform_stripped_oid(".1.3.6.1.4.1.1916.1.16.2.1.5", $device);
        $atEntries = array();
        if (sizeof($FdbPortIfIndex)) {
            mactrack_debug("FdbPortIfIndex data collection complete");
            $FdbMacAddress = xform_stripped_oid(".1.3.6.1.4.1.1916.1.16.2.1.3", $device);
            mactrack_debug("FdbMacAddress data collection complete");
            $FdbIPAddress = xform_stripped_oid(".1.3.6.1.4.1.1916.1.16.2.1.2", $device);
            mactrack_debug("FdbIPAddress data collection complete");
            $FdbVlanIfIndex = xform_stripped_oid(".1.3.6.1.4.1.1916.1.16.2.1.4", $device);
            mactrack_debug("FdbVlanIfIndex data collection complete");
            $VlanIfVlanId = xform_stripped_oid(".1.3.6.1.4.1.1916.1.2.1.2.1.10", $device);
            mactrack_debug("VlanIfVlanId data collection complete");
            $BasePortIfIndex = xform_stripped_oid(".1.3.6.1.2.1.17.1.4.1.2", $device);
            mactrack_debug("BasePortIfIndex data collection complete");
            $ifName = xform_stripped_oid(".1.3.6.1.2.1.31.1.1.1.1", $device);
            mactrack_debug("ifName data collection complete");
        }
        $i = 0;
        if (sizeof($FdbPortIfIndex)) {
            foreach ($FdbPortIfIndex as $key => $PortIndex) {
                $atEntries[$i]["atifIndex"] = $ifName[$BasePortIfIndex[$PortIndex]] . ", vlan:" . $VlanIfVlanId[$FdbVlanIfIndex[$key]];
                $atEntries[$i]["atPhysAddress"] = xform_mac_address($FdbMacAddress[$key]);
                $atEntries[$i]["atNetAddress"] = xform_net_address($FdbIPAddress[$key]);
                $i++;
            }
        }
        mactrack_debug("atEntries assembly complete.");
    }
    /* output details to database */
    if (sizeof($atEntries)) {
        foreach ($atEntries as $atEntry) {
            $insert_string = "REPLACE INTO mac_track_ips " . "(site_id,device_id,hostname,device_name,port_number," . "mac_address,ip_address,scan_date)" . " VALUES ('" . $device["site_id"] . "','" . $device["device_id"] . "','" . $device["hostname"] . "','" . $device["device_name"] . "','" . $atEntry["atifIndex"] . "','" . $atEntry["atPhysAddress"] . "','" . $atEntry["atNetAddress"] . "','" . $scan_date . "')";
            //mactrack_debug("SQL: " . $insert_string);
            db_execute($insert_string);
        }
    }
    /* save ip information for the device */
    $device["ips_total"] = sizeof($atEntries);
    db_execute("UPDATE mac_track_devices SET ips_total ='" . $device["ips_total"] . "' WHERE device_id='" . $device["device_id"] . "'");
    mactrack_debug("HOST: " . $device["hostname"] . ", IP address information collection complete: nb IP=" . sizeof($atEntries) . ".");
}
function get_foundry_switch_ports($site, &$device, $lowPort = 0, $highPort = 0)
{
    global $debug, $scan_date;
    /* initialize port counters */
    $device["ports_total"] = 0;
    $device["ports_active"] = 0;
    $device["ports_trunk"] = 0;
    $device["vlans_total"] = 0;
    $device["ports_dual_mode"] = 0;
    /* get VLAN information */
    $vlan_ids = xform_standard_indexed_data(".1.3.6.1.4.1.1991.1.1.3.2.7.1.21", $device);
    /* get VLAN Trunk status */
    $vlan_trunkstatus = xform_standard_indexed_data(".1.3.6.1.4.1.1991.1.1.3.3.5.1.4", $device);
    $device["vlans_total"] = sizeof($vlan_trunkstatus);
    mactrack_debug("VLAN data collected. There are " . sizeof($vlan_ids) . " VLANS.");
    /* get the ifIndexes for the device */
    $ifIndexes = xform_standard_indexed_data(".1.3.6.1.2.1.2.2.1.1", $device);
    mactrack_debug("ifIndexes data collection complete");
    /* get the ifTypes for the device */
    $ifTypes = xform_standard_indexed_data(".1.3.6.1.2.1.2.2.1.3", $device);
    mactrack_debug("ifTypes data collection complete.");
    /* get the ifNames for the device */
    $ifNames = xform_standard_indexed_data(".1.3.6.1.2.1.31.1.1.1.1", $device);
    mactrack_debug("ifNames data collection complete.");
    /* get ports that happen to be link ports */
    $link_ports = get_link_port_status($device);
    mactrack_debug("ipAddrTable scanning for link ports data collection complete.");
    /* get ports that have no vlan id (non dual-mode) */
    $port_dualmode = xform_standard_indexed_data(".1.3.6.1.4.1.1991.1.1.3.3.5.1.24", $device);
    mactrack_debug("ifVlanId data collection complete.");
    if (sizeof($ifIndexes)) {
        foreach ($ifIndexes as $ifIndex) {
            $ifInterfaces[$ifIndex]["ifIndex"] = $ifIndex;
            $ifInterfaces[$ifIndex]["ifName"] = @$ifNames[$ifIndex];
            $ifInterfaces[$ifIndex]["ifType"] = $ifTypes[$ifIndex];
            $ifInterfaces[$ifIndex]["linkPort"] = @$link_ports[$ifIndex];
            $ifInterfaces[$ifIndex]["trunkPortState"] = @$vlan_trunkstatus[$ifIndex];
            $ifInterfaces[$ifIndex]["ifVlanId"] = @$port_dualmode[$ifIndex];
        }
    }
    mactrack_debug("ifInterfaces assembly complete.");
    /* calculate the number of end user ports */
    if (sizeof($ifTypes)) {
        foreach ($ifTypes as $ifType) {
            if ($ifType >= 6 && $ifType <= 9) {
                $device["ports_total"]++;
            }
        }
    }
    mactrack_debug("Total Ports = " . $device["ports_total"]);
    /* calculate the number of trunk ports */
    if (sizeof($ifIndexes)) {
        foreach ($ifIndexes as $ifIndex) {
            if ($ifInterfaces[$ifIndex]["trunkPortState"] == 1 && $ifInterfaces[$ifIndex]["ifVlanId"] == 0) {
                $device["ports_trunk"]++;
            }
        }
    }
    mactrack_debug("Total Trunk Ports = " . $device["ports_trunk"]);
    /* get VLAN details */
    $i = 0;
    if (sizeof($vlan_ids)) {
        foreach ($vlan_ids as $vlan_id => $vlan_name) {
            $active_vlans[$i]["vlan_id"] = $vlan_id;
            $active_vlans[$i]["vlan_name"] = $vlan_name;
            $active_vlans++;
            mactrack_debug("VLAN ID = " . $active_vlans[$i]["vlan_id"] . " VLAN Name = " . $active_vlans[$i]["vlan_name"]);
            $i++;
        }
    }
    if (sizeof($active_vlans)) {
        /* get the port status information */
        $port_results = get_base_dot1dTpFdbEntry_ports($site, $device, $ifInterfaces, "", "", FALSE);
        $port_vlan_data = xform_standard_indexed_data(".1.3.6.1.4.1.1991.1.1.3.2.6.1.1", $device);
        $i = 0;
        $j = 0;
        $port_array = array();
        if (sizeof($port_results)) {
            foreach ($port_results as $port_result) {
                $ifIndex = $port_result["port_number"];
                $ifType = $ifTypes[$ifIndex];
                $ifName = $ifNames[$ifIndex];
                $portName = $ifName;
                $portTrunkStatus = @$ifInterfaces[$ifIndex]["trunkPortState"];
                mactrack_debug("Port Number = " . $ifIndex . " Type = " . $ifType . " Name = " . $ifName . " Port Name = " . $portName . " Trunk Status = " . $portTrunkStatus);
                /* only output legitimate end user ports */
                if ($ifType >= 6 && $ifType <= 9) {
                    $port_array[$i]["vlan_id"] = @$port_vlan_data[$port_result["port_number"]];
                    $port_array[$i]["vlan_name"] = @$vlan_ids[$port_array[$i]["vlan_id"]];
                    $port_array[$i]["port_number"] = @$port_result["port_number"];
                    $port_array[$i]["port_name"] = $portName;
                    $port_array[$i]["mac_address"] = xform_mac_address($port_result["mac_address"]);
                    $device["ports_active"]++;
                    mactrack_debug("VLAN: " . $port_array[$i]["vlan_id"] . ", " . "NAME: " . $port_array[$i]["vlan_name"] . ", " . "PORT: " . $ifIndex . ", " . "NAME: " . $port_array[$i]["port_name"] . ", " . "MAC: " . $port_array[$i]["mac_address"]);
                    $i++;
                }
                $j++;
            }
            $active_ports_array = xform_standard_indexed_data(".1.3.6.1.2.1.2.2.1.8", $device);
            $indexes = array_keys($active_ports_array);
            $i = 0;
            if (sizeof($active_ports_array)) {
                foreach ($active_ports_array as $port_info) {
                    $port_info = mactrack_strip_alpha($port_info);
                    $ifInterfaces[$indexes[$i]]["ifType"] = mactrack_strip_alpha($ifInterfaces[$indexes[$i]]["ifType"]);
                    mactrack_debug($ifInterfaces[$indexes[$i]]["ifType"]);
                    if ($ifInterfaces[$indexes[$i]]["ifType"] >= 6 && $ifInterfaces[$indexes[$i]]["ifType"] <= 9 || $ifInterfaces[$indexes[$i]]["ifType"] == 71) {
                        if ($port_info == 1) {
                            $device["ports_active"]++;
                        }
                        $i++;
                    }
                }
            }
            $device["ports_active"] = $device["ports_active"] - $device["ports_trunk"];
            /* get IP Addresses */
            $gateway = cacti_snmp_get($device["hostname"], $device["snmp_readstring"], ".1.3.6.1.4.1.1991.1.1.2.1.10.0", $device["snmp_version"], $device["snmp_username"], $device["snmp_password"], $device["snmp_auth_protocol"], $device["snmp_priv_passphrase"], $device["snmp_priv_protocol"], $device["snmp_context"], $device["snmp_port"], $device["snmp_timeout"], $device["snmp_retries"]);
            mactrack_debug("INFO: GATEWAY: " . $gateway);
            /* display completion message */
            print "INFO: HOST: " . $device["hostname"] . ", TYPE: " . substr($device["snmp_sysDescr"], 0, 40) . ", TOTAL PORTS: " . $device["ports_total"] . ", ACTIVE PORTS: " . $device["ports_active"];
            $device["last_runmessage"] = "Data collection completed ok";
            $device["macs_active"] = sizeof($port_array);
            db_store_device_port_results($device, $port_array, $scan_date);
        }
    } else {
        print "INFO: HOST: " . $device["hostname"] . ", TYPE: " . substr($device["snmp_sysDescr"], 0, 40) . ", No active devices on this network device.";
        $device["snmp_status"] = HOST_UP;
        $device["last_runmessage"] = "Data collection completed ok. No active devices on this network device.";
    }
    return $device;
}
function get_repeater_rev4_ports($site, &$device, $lowPort, $highPort)
{
    global $debug, $scan_date;
    $snmp_readstring = get_repeater_snmp_readstring($device);
    if (strlen($snmp_readstring) > 0) {
        $ports_active = @cacti_snmp_get($device["hostname"], $snmp_readstring, ".1.3.6.1.4.1.52.4.1.1.1.4.1.1.5.0", $device["snmp_version"], $device["snmp_username"], $device["snmp_password"], $device["snmp_auth_protocol"], $device["snmp_priv_passphrase"], $device["snmp_priv_protocol"], $device["snmp_context"], $device["snmp_port"], $device["snmp_timeout"], $device["snmp_retries"]) - 1;
        $ports_total = @cacti_snmp_get($device["hostname"], $snmp_readstring, ".1.3.6.1.4.1.52.4.1.1.1.4.1.1.4.0", $device["snmp_version"], $device["snmp_username"], $device["snmp_password"], $device["snmp_auth_protocol"], $device["snmp_priv_passphrase"], $device["snmp_priv_protocol"], $device["snmp_context"], $device["snmp_port"], $device["snmp_timeout"], $device["snmp_retries"]) - 1;
        /* get the ignore ports list */
        $ignore_ports = port_list_to_array($device["ignorePorts"]);
        print "INFO: HOST: " . $device["hostname"] . ", TYPE: " . substr($device["snmp_sysDescr"], 0, 40) . ", TOTAL PORTS: " . $ports_total . ", ACTIVE PORTS: " . $ports_active;
        if ($debug) {
            print "\n";
        }
        $device["vlans_total"] = 0;
        $device["ports_total"] = $ports_total;
        if ($ports_active >= 0) {
            $device["ports_active"] = $ports_active;
        } else {
            $device["ports_active"] = 0;
        }
        if ($device["snmp_version"] == 2) {
            $snmp_version = "2c";
        } else {
            $snmp_version = $device["snmp_version"];
        }
        $port_keys = array();
        $return_array = array();
        $new_port_key_array = array();
        $port_number = 0;
        $nextOID = ".1.3.6.1.4.1.52.4.1.1.1.4.1.5.2.1.2";
        $to = ceil($device["snmp_timeout"] / 1000);
        $i = 0;
        $previous_port = 0;
        while (1) {
            $exec_string = trim(read_config_option("path_snmpgetnext") . " -c " . $snmp_readstring . " -OnUQ -v " . $snmp_version . " -r " . $device["snmp_retries"] . " -t " . $to . " " . $device["hostname"] . ":" . $device["snmp_port"] . " " . $nextOID);
            exec($exec_string, $return_array, $return_code);
            list($nextOID, $port_number) = explode("=", $return_array[$i]);
            if ($port_number < $previous_port) {
                break;
            }
            if ($port_number <= $highPort && $port_number >= $lowPort) {
                if (!in_array($port_number, $ignore_ports)) {
                    /* set defaults for devices in case they don't have/support vlans */
                    $new_port_key_array[$i]["vlan_id"] = "N/A";
                    $new_port_key_array[$i]["vlan_name"] = "N/A";
                    $new_port_key_array[$i]["port_name"] = "N/A";
                    $new_port_key_array[$i]["key"] = trim(substr($nextOID, 36));
                    $new_port_key_array[$i]["port_number"] = trim(strtr($port_number, " ", ""));
                }
                $previous_port = trim(strtr($port_number, " ", ""));
            } else {
                break;
            }
            mactrack_debug("CMD: " . $exec_string . ", PORT: " . $port_number);
            $i++;
            $port_number = "";
        }
        if (sizeof($new_port_key_array) > 0) {
            /* map mac address */
            $i = 0;
            foreach ($new_port_key_array as $port_key) {
                $OID = ".1.3.6.1.4.1.52.4.1.1.1.4.1.5.2.1.1." . $port_key["key"];
                $mac_address = @cacti_snmp_get($device["hostname"], $snmp_readstring, $OID, $device["snmp_version"], $device["snmp_username"], $device["snmp_password"], $device["snmp_auth_protocol"], $device["snmp_priv_passphrase"], $device["snmp_priv_protocol"], $device["snmp_context"], $device["snmp_port"], $device["snmp_timeout"], $device["snmp_retries"]);
                $new_port_key_array[$i]["mac_address"] = xform_mac_address($mac_address);
                mactrack_debug("OID: " . $OID . ", MAC ADDRESS: " . $new_port_key_array[$i]["mac_address"]);
                $i++;
            }
            $device["last_runmessage"] = "Data collection completed ok";
        } else {
            mactrack_debug("INFO: The following device has no active ports: " . $site . "/" . $device["hostname"] . "\n");
            $device["last_runmessage"] = "Data collection completed ok";
        }
    } else {
        mactrack_debug("ERROR: Could not determine snmp_readstring for host: " . $site . "/" . $device["hostname"] . "\n");
        $device["snmp_status"] = HOST_ERROR;
        $device["last_runmessage"] = "ERROR: Could not determine snmp_readstring for host.";
    }
    if (!$debug) {
        print " - Complete\n";
    }
    $device["ports_active"] = $ports_active;
    $device["macs_active"] = sizeof($new_port_key_array);
    db_store_device_port_results($device, $new_port_key_array, $scan_date);
    return $device;
}
Example #10
0
function get_procurve_switch_ports($site, &$device, $lowPort = 0, $highPort = 0)
{
    global $debug, $scan_date;
    /* initialize port counters */
    $device["ports_total"] = 0;
    $device["ports_active"] = 0;
    $device["ports_trunk"] = 0;
    $active_vlans = array();
    /* get VLAN information */
    $vlan_ids = xform_standard_indexed_data(".1.3.6.1.4.1.11.2.14.11.5.1.3.1.1.4.1.2", $device);
    /* get VLAN Trunk status */
    $vlan_trunkstatus = xform_standard_indexed_data(".1.3.6.1.4.1.11.2.14.11.5.1.3.1.1.8.1.1.1", $device);
    $device["vlans_total"] = sizeof($vlan_ids);
    mactrack_debug("VLAN data collected. There are " . sizeof($vlan_ids) . " VLANS.");
    /* get the ifIndexes for the device */
    $ifIndexes = xform_standard_indexed_data(".1.3.6.1.2.1.2.2.1.1", $device);
    mactrack_debug("ifIndexes data collection complete");
    /* get and store the interfaces table */
    $ifInterfaces = build_InterfacesTable($device, $ifIndexes, TRUE, FALSE);
    if (sizeof($ifIndexes)) {
        foreach ($ifIndexes as $ifIndex) {
            $ifInterfaces[$ifIndex]["trunkPortState"] = @$vlan_trunkstatus[$ifIndex];
            if ($ifInterfaces[$ifIndex]["ifType"] >= 6 && $ifInterfaces[$ifIndex]["ifType"] <= 9) {
                $device["ports_total"]++;
            }
            if ($ifInterfaces[$ifIndex]["trunkPortState"] == 3) {
                $device["ports_trunk"]++;
            }
        }
    }
    mactrack_debug("ifInterfaces assembly complete.");
    $i = 0;
    if (sizeof($vlan_ids)) {
        foreach ($vlan_ids as $vlan_id => $vlan_name) {
            $active_vlans[$i]["vlan_id"] = $vlan_id;
            $active_vlans[$i]["vlan_name"] = $vlan_name;
            $active_vlans++;
            $i++;
        }
    }
    if (sizeof($active_vlans)) {
        $i = 0;
        /* get the port status information */
        $port_results = get_base_dot1dTpFdbEntry_ports($site, $device, $ifInterfaces, "", "", FALSE);
        $port_vlan_data = xform_standard_indexed_data(".1.3.6.1.4.1.11.2.14.11.5.1.3.1.1.5.1.2", $device);
        $i = 0;
        $j = 0;
        $port_array = array();
        if (sizeof($port_results)) {
            foreach ($port_results as $port_result) {
                $ifIndex = $port_result["port_number"];
                $ifType = $ifInterfaces[$ifIndex]["ifType"];
                $ifName = $ifInterfaces[$ifIndex]["ifName"];
                $portName = $ifName;
                $portTrunkStatus = @$ifInterfaces[$ifIndex]["trunkPortState"];
                /* only output legitamate end user ports */
                if ($ifType >= 6 && $ifType <= 9) {
                    $port_array[$i]["vlan_id"] = @$port_vlan_data[$port_result["port_number"]];
                    $port_array[$i]["vlan_name"] = @$vlan_ids[$port_array[$i]["vlan_id"]];
                    $port_array[$i]["port_number"] = @$port_result["port_number"];
                    $port_array[$i]["port_name"] = $portName;
                    $port_array[$i]["mac_address"] = xform_mac_address($port_result["mac_address"]);
                    $device["ports_active"]++;
                    mactrack_debug("VLAN: " . $port_array[$i]["vlan_id"] . ", " . "NAME: " . $port_array[$i]["vlan_name"] . ", " . "PORT: " . $ifIndex . ", " . "NAME: " . $port_array[$i]["port_name"] . ", " . "MAC: " . $port_array[$i]["mac_address"]);
                    $i++;
                }
                $j++;
            }
        }
        /* display completion message */
        print "INFO: HOST: " . $device["hostname"] . ", TYPE: " . substr($device["snmp_sysDescr"], 0, 40) . ", TOTAL PORTS: " . $device["ports_total"] . ", ACTIVE PORTS: " . $device["ports_active"];
        $device["last_runmessage"] = "Data collection completed ok";
        $device["macs_active"] = sizeof($port_array);
        db_store_device_port_results($device, $port_array, $scan_date);
    } else {
        print "INFO: HOST: " . $device["hostname"] . ", TYPE: " . substr($device["snmp_sysDescr"], 0, 40) . ", No active devcies on this network device.";
        $device["snmp_status"] = HOST_UP;
        $device["last_runmessage"] = "Data collection completed ok. No active devices on this network device.";
    }
    return $device;
}
function get_netscreen_arp_table($site, &$device)
{
    global $debug, $scan_date;
    /* get the atifIndexes for the device */
    $atifIndexes = xform_indexed_data('.1.3.6.1.2.1.3.1.1.1', $device, 6);
    if (sizeof($atifIndexes)) {
        $ifIntcount = 1;
    } else {
        $ifIntcount = 0;
    }
    if ($ifIntcount != 0) {
        $atifIndexes = xform_indexed_data('.1.3.6.1.2.1.4.22.1.1', $device, 5);
    }
    mactrack_debug(__('atifIndexes data collection complete'));
    /* get the atPhysAddress for the device */
    if ($ifIntcount != 0) {
        $atPhysAddress = xform_indexed_data('.1.3.6.1.2.1.4.22.1.2', $device, 5);
    } else {
        $atPhysAddress = xform_indexed_data('.1.3.6.1.2.1.3.1.1.2', $device, 6);
    }
    /* convert the mac address if necessary */
    $keys = array_keys($atPhysAddress);
    $i = 0;
    if (sizeof($atPhysAddress)) {
        foreach ($atPhysAddress as $atAddress) {
            $atPhysAddress[$keys[$i]] = xform_mac_address($atAddress);
            $i++;
        }
    }
    mactrack_debug(__('atPhysAddress data collection complete'));
    /* get the atPhysAddress for the device */
    if ($ifIntcount != 0) {
        $atNetAddress = xform_indexed_data('.1.3.6.1.2.1.4.22.1.3', $device, 5);
    } else {
        $atNetAddress = xform_indexed_data('.1.3.6.1.2.1.3.1.1.3', $device, 6);
    }
    mactrack_debug(__('atNetAddress data collection complete'));
    /* get the ifNames for the device */
    $keys = array_keys($atifIndexes);
    $i = 0;
    if (sizeof($atifIndexes)) {
        foreach ($atifIndexes as $atifIndex) {
            $atEntries[$i]['atifIndex'] = $atifIndex;
            $atEntries[$i]['atPhysAddress'] = $atPhysAddress[$keys[$i]];
            $atEntries[$i]['atNetAddress'] = xform_net_address($atNetAddress[$keys[$i]]);
            $i++;
        }
    }
    mactrack_debug(__('atEntries assembly complete.'));
    /* output details to database */
    if (sizeof($atEntries)) {
        foreach ($atEntries as $atEntry) {
            $insert_string = 'REPLACE INTO mac_track_ips 
				(site_id,device_id,hostname,device_name,port_number,
				mac_address,ip_address,scan_date)
				 VALUES (' . $device['site_id'] . ',' . $device['device_id'] . ',' . db_qstr($device['hostname']) . ',' . db_qstr($device['device_name']) . ',' . db_qstr($atEntry['atifIndex']) . ',' . db_qstr($atEntry['atPhysAddress']) . ',' . db_qstr($atEntry['atNetAddress']) . ',' . db_qstr($scan_date) . ')';
            db_execute($insert_string);
        }
    }
    /* save ip information for the device */
    $device['ips_total'] = sizeof($atEntries);
    db_execute('UPDATE mac_track_devices SET ips_total =' . $device['ips_total'] . ' WHERE device_id=' . $device['device_id']);
    mactrack_debug(__('HOST: %s, IP address information collection complete', $device['hostname']));
}
Example #12
0
function get_norbay_switch_ports($site, &$device, $lowPort = 0, $highPort = 0)
{
    global $debug, $scan_date;
    /* initialize port counters */
    $device["ports_total"] = 0;
    $device["ports_active"] = 0;
    $device["ports_trunk"] = 0;
    /* get VLAN information */
    $vlan_ids = xform_standard_indexed_data(".1.3.6.1.4.1.2272.1.3.2.1.2", $device);
    $vlan_trunkstatus = xform_standard_indexed_data(".1.3.6.1.4.1.2272.1.3.3.1.4", $device);
    $device["vlans_total"] = sizeof($vlan_ids);
    mactrack_debug("There are " . sizeof($vlan_ids) . " VLANS.");
    /* get the ifIndexes for the device */
    $ifIndexes = xform_standard_indexed_data(".1.3.6.1.2.1.2.2.1.1", $device);
    mactrack_debug("ifIndexes data collection complete");
    /* get and store the interfaces table */
    $ifInterfaces = build_InterfacesTable($device, $ifIndexes, TRUE, FALSE);
    if (sizeof($ifIndexes)) {
        foreach ($ifIndexes as $ifIndex) {
            $ifInterfaces[$ifIndex]["trunkPortState"] = @$vlan_trunkstatus[$ifIndex];
            $ifInterfaces[$ifIndex]["vlannum"] = @$vlan_ids[$ifIndex];
            $ifInterfaces[$ifIndex]["ifOperStatus"] = mactrack_strip_alpha($ifInterfaces[$ifIndex]["ifOperStatus"]);
            if ($ifInterfaces[$ifIndex]["ifType"] == 6) {
                $device["ports_total"]++;
            }
            if ($ifInterfaces[$ifIndex]["ifOperStatus"] == 1) {
                $device["ports_active"]++;
            }
            if ($ifInterfaces[$ifIndex]["trunkPortState"] == 2) {
                mactrack_debug("Found Port Trunk: " . $ifInterfaces[$ifIndex]["ifDescr"]);
                $device["ports_trunk"]++;
            }
        }
    }
    mactrack_debug("ifInterfaces assembly complete.");
    $i = 0;
    if (sizeof($vlan_ids)) {
        foreach ($vlan_ids as $vlan_id => $vlan_name) {
            $active_vlans[$i]["vlan_id"] = $vlan_id;
            $active_vlans[$i]["vlan_name"] = $vlan_name;
            $active_vlans++;
            $i++;
        }
    }
    if (sizeof($active_vlans)) {
        $i = 0;
        /* get the port status information */
        $port_results = get_base_dot1dTpFdbEntry_ports($site, $device, $ifInterfaces, "", "", FALSE);
        $port_vlan_data = xform_dot1q_vlan_associations($device);
        $i = 0;
        $j = 0;
        $port_array = array();
        if (sizeof($port_results)) {
            foreach ($port_results as $port_result) {
                $ifIndex = $port_result["port_number"];
                $ifType = $ifInterfaces[$ifIndex]["ifType"];
                $ifName = $ifInterfaces[$ifIndex]["ifName"];
                $ifDescr = $ifInterfaces[$ifIndex]["ifDescr"];
                if (strpos($ifDescr, "BayStack") === false) {
                    $portName = preg_replace("/ifc[0-9]+ /", "", $ifName);
                } else {
                    $portName = preg_replace("/BayStack - /", "", $ifDescr);
                }
                $portTrunkStatus = @$ifInterfaces[$ifIndex]["trunkPortState"];
                /* only output legitamate end user ports */
                if ($ifType == 6 && $portTrunkStatus == 1) {
                    $port_array[$i]["vlan_id"] = @$port_vlan_data[$port_result["key"]];
                    $port_array[$i]["vlan_name"] = @$vlan_ids[$port_array[$i]["vlan_id"]];
                    $port_array[$i]["port_number"] = @$port_result["port_number"];
                    $port_array[$i]["port_name"] = $portName;
                    $port_array[$i]["mac_address"] = xform_mac_address($port_result["mac_address"]);
                    $device["ports_active"]++;
                    foreach ($port_array as $test_array) {
                        if ($test_array["port_name"] == $portName && $test_array["mac_address"] != $port_result["mac_address"]) {
                            $port_array[$i]["port_number"] = @$port_result["port_number"] . " - *";
                        }
                    }
                    mactrack_debug("VLAN: " . $port_array[$i]["vlan_id"] . ", " . "NAME: " . $port_array[$i]["vlan_name"] . ", " . "PORT: " . $ifInterfaces[$ifIndex]["ifName"] . ", " . "NUMBER: " . $port_array[$i]["port_number"] . ", " . "NAME: " . $port_array[$i]["port_name"] . ", " . "MAC: " . $port_array[$i]["mac_address"]);
                    $i++;
                }
                $j++;
            }
        }
        /* display completion message */
        print "INFO: HOST: " . $device["hostname"] . ", TYPE: " . trim(substr($device["snmp_sysDescr"], 0, 40)) . ", TOTAL PORTS: " . $device["ports_total"] . ", ACTIVE PORTS: " . $device["ports_active"];
        $device["last_runmessage"] = "Data collection completed ok";
        $device["macs_active"] = sizeof($port_array);
        db_store_device_port_results($device, $port_array, $scan_date);
    } else {
        print "INFO: HOST: " . $device["hostname"] . ", TYPE: " . substr($device["snmp_sysDescr"], 0, 40) . ", No active devcies on this network device.";
        $device["snmp_status"] = HOST_UP;
        $device["last_runmessage"] = "Data collection completed ok. No active devices on this network device.";
    }
    return $device;
}