Version: 0.1b
Type: Full Script
Category: HTTP
License: GNU General Public License
Description: This script will output the current active HTTP sessions on any web server by querying the respective SNMP OID. You need to have the php_snmp.dll extension enabled in your php.ini file and also have the 'extensions' directory set. Your server should also be running SNMP as a service.
<?php
# HTTP Session Identifier using SNMP
# 1st April 2001, Sheran A. Gunasekera
#
# PHP Version: php 4.0.4pl1
# Script Version: 0.1b
#
header("Pragma: no-cache"); # Make sure the HTML document is not cached at the Browser
header("Refresh: 30"); # Refresh the document every 30 seconds
?>
<html>
<title>HTTP Sessions established on the <Hostname goes here> Server</title>
<body>
<h3>HTTP Sessions established as at
<?php
$tm=strftime("%I:%M%p"); # Format the current time to H:M AM/PM
echo $tm;
?> </h3>
<table>
<?php
$a= snmpwalk("127.0.0.1", "public", ".1.3.6.1.2.1.6.13.1.4.10.1.10.24.80"); # Get the Connections to Port 80 on the specified Host using SNMP into array $a
$b= array_unique($a); # Get all of the unique IP's from the array...
$c= array_keys($b); # ...also ensure that you get the correct array keys
for ($p=0; $p<count($c); $p++)
{
$sp=substr($b[$c[$p]],11,-1); # Place the IP Address in a string
$fin=gethostbyaddr($sp); # Get the host name of the IP Address (You can comment this out if you are on an Private LAN with no Internet Access)
echo "<tr><td>IP: ".$sp."</td><td>Hostname: ".$fin."</td></tr>"; # Output the results
}
?>
</table>
</body>
</html>