function get_enterasys_N7_dot1dTpFdbEntry_ports($site, &$device, &$ifInterfaces, $snmp_readstring = "", $store_to_db = TRUE, $lowPort = 1, $highPort = 9999) { global $debug, $scan_date; mactrack_debug("FUNCTION: get_enterasys_N7_dot1dTpFdbEntry_ports started"); /* initialize variables */ $port_keys = array(); $return_array = array(); $new_port_key_array = array(); $port_key_array = 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); mactrack_debug("get active ports: " . sizeof($active_ports_array)); $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) { 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: dot1dBasePortIfIndex from dot1dBasePortTable GET NEXT: 1.3.6.1.2.1.17.1.4.1.2.1: 1 GET NEXT: 1.3.6.1.2.1.17.1.4.1.2.2: 4 GET NEXT: 1.3.6.1.2.1.17.1.4.1.2.64: 12001 GET NEXT: 1.3.6.1.2.1.17.1.4.1.2.65: 12002 GET NEXT: 1.3.6.1.2.1.17.1.4.1.2.66: 12003 GET NEXT: 1.3.6.1.2.1.17.1.4.1.2.67: 12004 GET NEXT: 1.3.6.1.2.1.17.1.4.1.2.68: 12005 GET NEXT: 1.3.6.1.2.1.17.1.4.1.2.69: 12006 GET NEXT: 1.3.6.1.2.1.17.1.4.1.2.70: 12007 where table index = bridge port (dot1dBasePort) and table value = ifIndex */ /* -------------------------------------------- */ $bridgePortIfIndexes = xform_standard_indexed_data(".1.3.6.1.2.1.17.1.4.1.2", $device, $snmp_readstring); mactrack_debug("get bridgePortIfIndexes: " . sizeof($bridgePortIfIndexes)); /* get port status: dot1dTpFdbStatus from dot1dTpFdbTable GET NEXT: 1.3.6.1.2.1.17.4.3.1.3.0.0.94.0.1.1: 3 GET NEXT: 1.3.6.1.2.1.17.4.3.1.3.0.1.227.32.11.99: 3 GET NEXT: 1.3.6.1.2.1.17.4.3.1.3.0.1.227.37.228.26: 3 GET NEXT: 1.3.6.1.2.1.17.4.3.1.3.0.1.227.37.238.180: 3 GET NEXT: 1.3.6.1.2.1.17.4.3.1.3.0.1.230.56.96.234: 3 GET NEXT: 1.3.6.1.2.1.17.4.3.1.3.0.1.230.59.133.114: 3 GET NEXT: 1.3.6.1.2.1.17.4.3.1.3.0.1.230.107.157.61: 3 GET NEXT: 1.3.6.1.2.1.17.4.3.1.3.0.1.230.107.189.168: 3 GET NEXT: 1.3.6.1.2.1.17.4.3.1.3.0.1.230.109.208.105: 3 where table index = MAC Address (dot1dTpFdbAddress e.g. 0.0.94.0.1.1 = 00:00:5E:00:01:01) and table value = port status (other(1), invalid(2), learned(3), self(4), mgmt(5)*/ /* -------------------------------------------- */ $port_status = xform_stripped_oid(".1.3.6.1.2.1.17.4.3.1.3", $device, $snmp_readstring); mactrack_debug("get port_status: " . sizeof($port_status)); /* get device active port numbers: dot1dTpFdbPort from dot1dTpFdbTable GET NEXT: 1.3.6.1.2.1.17.4.3.1.2.0.0.94.0.1.1: 72 GET NEXT: 1.3.6.1.2.1.17.4.3.1.2.0.1.227.32.11.99: 70 GET NEXT: 1.3.6.1.2.1.17.4.3.1.2.0.1.227.37.228.26: 70 GET NEXT: 1.3.6.1.2.1.17.4.3.1.2.0.1.227.37.238.180: 70 GET NEXT: 1.3.6.1.2.1.17.4.3.1.2.0.1.230.56.96.234: 70 GET NEXT: 1.3.6.1.2.1.17.4.3.1.2.0.1.230.59.133.114: 69 GET NEXT: 1.3.6.1.2.1.17.4.3.1.2.0.1.230.107.157.61: 70 GET NEXT: 1.3.6.1.2.1.17.4.3.1.2.0.1.230.107.189.168: 68 GET NEXT: 1.3.6.1.2.1.17.4.3.1.2.0.1.230.109.208.105: 68 where table index = MAC Address (dot1dTpFdbAddress e.g. 0.0.94.0.1.1 = 00:00:5E:00:01:01) and table value = bridge port */ /* -------------------------------------------- */ $port_numbers = xform_stripped_oid(".1.3.6.1.2.1.17.4.3.1.2", $device, $snmp_readstring); mactrack_debug("get port_numbers: " . sizeof($port_numbers)); /* get VLAN information */ /* -------------------------------------------- */ #$vlan_ids = xform_enterasys_N7_vlan_associations($device, $snmp_readstring); $vlan_ids = xform_dot1q_vlan_associations($device, $snmp_readstring); mactrack_debug("get vlan_ids: " . sizeof($vlan_ids)); #print_r($vlan_ids); /* 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) { /* key = MAC Address from dot1dTpFdbTable */ /* value = bridge port */ if ($highPort == 0 || $port_number >= $lowPort && $port_number <= $highPort) { if (!in_array($port_number, $ignore_ports)) { if (@$port_status[$key] == "3") { $port_key_array[$i]["key"] = $key; $port_key_array[$i]["port_number"] = $port_number; #print("i: $i, Key: " . $port_key_array[$i]["key"] . ", Number: $port_number\n"); $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 */ #print("searching bridge port: " . $port_key["port_number"] .", Bridge: " . $bridgePortIfIndexes[$port_key["port_number"]] . "\n"); 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 && !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"] = @$brPortIfIndex; $new_port_key_array[$i]["vlan_id"] = @$vlan_ids[$port_key["key"]]; #print_r($new_port_key_array[$i]); $i++; } } } mactrack_debug("Port number information collected: " . sizeof($new_port_key_array)); /* 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: " . sizeof($port_macs)); } 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; } }
function get_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_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"]; mactrack_debug($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; if (sizeof($active_ports_array)) { foreach ($active_ports_array as $port_info) { $port_info = mactrack_strip_alpha($port_info); if (@$ifInterfaces[$indexes[$i]]["ifType"] >= 6 && @$ifInterfaces[$indexes[$i]]["ifType"] <= 9 || @$ifInterfaces[$indexes[$i]]["ifType"] == 71) { 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) { $dot1dBasePortIfIndex = ".1.3.6.1.2.1.17.1.4.1.2"; /* get bridge port to ifIndex mapping */ $bridgePortIfIndexes_temp = xform_standard_indexed_data($dot1dBasePortIfIndex, $device, $snmp_readstring); $bridgePortIfIndexes = array(); $to_remove = 'mib-2.17.' . substr($dot1dBasePortIfIndex, strpos($dot1dBasePortIfIndex, '.17.') + 4) . '.'; foreach ($bridgePortIfIndexes_temp as $key => $index) { $bridgePortIfIndexes[str_replace($to_remove, '', $key)] = $index; } $dot1dTpFdbStatus = ".1.3.6.1.2.1.17.4.3.1.3"; /* get device active port statuses */ $port_status_temp = xform_stripped_oid($dot1dTpFdbStatus, $device, $snmp_readstring); $port_status = array(); $to_remove = 'mib-2.17.' . substr($dot1dTpFdbStatus, strpos($dot1dTpFdbStatus, '.17.') + 4) . '.'; foreach ($port_status_temp as $key => $status) { $port_status[str_replace($to_remove, '', $key)] = $status; } $dot1dTpFdbPort = ".1.3.6.1.2.1.17.4.3.1.2"; /* get device active port numbers */ $port_numbers_temp = xform_stripped_oid($dot1dTpFdbPort, $device, $snmp_readstring); $port_numbers = array(); $to_remove = 'mib-2.17.' . substr($dot1dTpFdbPort, strpos($dot1dTpFdbPort, '.17.') + 4) . '.'; foreach ($port_numbers_temp as $key => $status) { $port_numbers[str_replace($to_remove, '', $key)] = $status; } /* 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; if (sizeof($port_numbers)) { foreach ($port_numbers as $key => $port_number) { if ($highPort == 0 || $port_number >= $lowPort && $port_number <= $highPort) { if (!in_array($port_number, $ignore_ports)) { if (@$port_status[$key] == "3" || @$port_status[$key] == "5") { $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; if (sizeof($port_key_array)) { 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)) { /* 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 && !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"] = @$ifInterfaces[$brPortIfIndex]["ifName"]; /* 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"]; $i++; } } } } mactrack_debug("Port number information collected."); /* map mac address */ /* only continue if there were user ports defined */ if (sizeof($new_port_key_array)) { $dot1dTpFdbAddress = ".1.3.6.1.2.1.17.4.3.1.1"; /* get the bridges active MAC addresses */ $port_macs_temp = xform_stripped_oid($dot1dTpFdbAddress, $device, $snmp_readstring); $port_macs = array(); $to_remove = 'mib-2.17.' . substr($dot1dTpFdbAddress, strpos($dot1dTpFdbAddress, '.17.') + 4) . '.'; foreach ($port_macs_temp as $key => $mac) { $port_macs[str_replace($to_remove, '', $key)] = $mac; } if (sizeof($port_macs)) { 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."); mactrack_debug("Starting port vlan information collection."); /* get VLAN information */ $vlan_ids = xform_dot1q_vlan_associations($device, $device["snmp_readstring"]); if (sizeof($vlan_ids)) { /* get the vlan names */ $vlan_names = xform_standard_indexed_data(".1.3.6.1.2.1.17.7.1.4.3.1.1", $device); foreach ($new_port_key_array as $key => $port_key) { $new_port_key_array[$key]["vlan_id"] = @$vlan_ids[$port_key["key"]]; $new_port_key_array[$key]["vlan_name"] = @$vlan_names[@$vlan_ids[$port_key["key"]]]; mactrack_debug("INDEX: '" . $key . "' VLAN: " . $new_port_key_array[$key]["vlan_id"] . "' Name: '" . $new_port_key_array[$key]["vlan_name"]); } } mactrack_debug("Port vlan 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)) { $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; } }
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; }