Just in case anyone else finds this useful, I quickly hacked this together.
If you save this as say switchport.php
Then access it with
http://openaudit/swithport.php?ip=192.1 ... ity=public
It connects to the switch/router/whatever with the specified ip address and community string using snmp and gets the mac address database. It then uses open-audit to get the names of machines for the mac addresses.
I've tried it with a few 3com and cisco switches. If you have closed vlan's then you will need to specify the vlan number in the uri. ( e.g.
http://openaudit/swithport.php?ip=192.1 ... ity=public
&vlan=200 )
[code]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<head>
<title>Switch</title>
</head>
<body>
<?php
include "include_config.php";
$dot1dTpFdbAddress = ".1.3.6.1.2.1.17.4.3.1.1";
$dot1dTpFdbPort = ".1.3.6.1.2.1.17.4.3.1.2";
$dot1dBasePortIfIndex = ".1.3.6.1.2.1.17.1.4.1.2";
$community = "public";
$ip = "";
if (isset($_REQUEST["ip"])) {
$ip = $_REQUEST["ip"];
}
if (isset($_REQUEST["community"])) {
$community = $_REQUEST["community"];
}
if (isset($_REQUEST["vlan"])) {
$community = $community . "@" . $_REQUEST["vlan"];
}
$db = mysql_connect($mysql_server, $mysql_user, $mysql_password) or die("Could not connect");
mysql_select_db($mysql_database) or die("Could not select database");
echo "<h1>" . gethostbyaddr($ip) . "</h1>\n";
snmp_set_oid_numeric_print(TRUE);
snmp_set_quick_print(TRUE);
snmp_set_enum_print(TRUE);
$addresses = snmprealwalk($ip, $community, $dot1dTpFdbAddress) or die("error dbAddress");
$ports = snmprealwalk($ip, $community, $dot1dTpFdbPort) or die("error dbPort");
$interfaces = snmprealwalk($ip, $community, $dot1dBasePortIfIndex) or die("error ifIndex");
asort($ports,SORT_NUMERIC);
echo "<table border=\"1\">\n";
echo "<tr><th>Port</th><th>Interface</th><th>MAC</th><th>Name</th><th>Description</th><th>IP</th></tr>\n";
foreach (array_keys($ports) as $oid) {
$macoid = $dot1dTpFdbAddress . substr($oid,23);
$mac = str_replace(" ",":",substr($addresses[$macoid],1,17));
$intoid = $dot1dBasePortIfIndex . "." . $ports[$oid];
echo "<tr>\n";
print "<td>$ports[$oid]</td><td>$interfaces[$intoid]</td><td>$mac</td>";
$sql = "select system_name, system_man_description, system.net_ip_address from system join network_card on net_uuid = system_uuid and net_timestamp = system_timestamp join system_man on system_uuid = system_man_uuid where net_mac_address = '$mac'";
$result = mysql_query($sql);
if (!$myrow = mysql_fetch_array($result)) {
$sql = "select other_network_name, other_description, other_ip_address from other where other_mac_address = '$mac'";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
}
print "<td>" . $myrow[0] . "</td>\n";
print "<td>" . $myrow[1] . "</td>\n";
print "<td>" . $myrow[2] . "</td>\n";
echo "</tr>\n";
}
echo "</table>\n";
?>
</body>
</html>
[/code]