Quicklinks
ActiveSocket provides an easy-to-use development interface to a variety of IP protocols. By using ActiveSocket, you can very easily create or enhance applications with network features.
ActiveSocket features the following: DNS, FTP, HTTP, HTTPs, ICMP Ping, IP-to-Country, MSN, NTP, RSH, SCP, SFTP, SNMP v1/v2c (Get, GetNext, Set), SNMP Traps, SNMP MIB, SSH, TCP, Telnet, TFTP, UDP, Telnet, Wake-On-LAN and more.SNMP can be well integrated into PHP environments. This document describes how ActiveSocket's SNMP objects can be integrated into PHP code. ActiveSocket is compliant with SNMP v1 and SNMP v2c. ActiveSocket automatically detects which SNMP version is running on the remote agent. Different SNMP data types, including:
The following operations are supported:
IMPORTANT: Make sure that the SNMP Service is installed and running on the machine where ActiveSocket is installed. For more details, please read FAQ items Q1200010 and Q1200015.
Download ActiveSocket from the ActiveXperts Download Site and start the installation. The installation guides you through the installation process.
First of all we need to collect information from the user. To connect properly to another computer/device, we need to know the hostname, the SNMP protocol it is using and the community of the computer/device. We also need to know what information must be sent to the computer/device. To collect this information in a webinterface, you need to create a form.
In the form we're using in this sample, we're working with 7 fields.
Our form louks like the image below
(Click on the picture to enlarge)
To verify if the form is submitted, we use the property "action" in the <form> tag. If the form is submitted, we navigate to index.php?method=submit. In php we fetch the variable "method" using $_GET['method'].
First of all we're going to fetch some variables. Using a loop we're executing all the filled in commands. We're executing the command using the function "execute_command()". We're doing that using this code:
//fetch the hostname $host = $_POST['host']; $community = $_POST['community']; $version = $_POST['version']; //walk through the 4 inputboxes, you can add more boxes if you like for($i = 1; $i < 5; $i++){ //again fetch some variables $boxname = "box" . $i; $boxvalue = $_POST[$boxname]; //execute the command, if there is a command if($boxvalue != ""){ execute_command($boxvalue, $host, $community, $version); } //close the loop }
The function looks like this:
function execute_command($command, $host, $community, $version){
//create the objects
$objSocket = new COM ("ActiveXperts.SnmpManager");
//initialise SNMP
$objSocket->Initialize;
//set version
$objSocket->ProtocolVersion = $version;
//open the object
$objSocket->open($host,$community);
//echo the results:
echo "<b>Result " . $command . ":</b><br>";
if($objSocket->LastError == 0){
//execute the command
$objGet = $objSocket->Get($command);
echo $objGet->Value . "<br>";
echo "<br>";
}
else{
//say out an error if the connection failed
echo "Sorry.... Connection failed!<br><br>";
}
//echo the error code
echo "<b>Errorcode</b><br>";
echo $objSocket->LastError . ":" . $objSocket->GetErrorDescription($objSocket->LastError) . "<br>";
echo "<br>";
echo "__________________________________________________";
echo "<br>";
echo "<br>";
//close the object
$objSocket->close;
//closing the function
}
There are many working samples included with the product. You can also find them on the ActiveXperts FTP site: ftp.activexperts-labs.com/samples/network-component.