• Twitter

Talking to a Ness / Elk M1 Panel via PHP

This is an example of one way to communicate with an Elk / Ness panel via PHP.

If you are looking for a much better way to go about it however – have a look at Remote Panel Access.

<?php
$ness = “192.168.100.1″;        # IP address or FQDN of your panel
$nessport = “2601″;             # Port you wish to connect to (generally 2601)
$usesecure = true;              # Connect with SSL (non zero) or Plain Text

$function = “ua004608″;         # Example “ct” to toggle a zone
$zone = “”;                     # Zone number / input number / output number

if ( $zone <> ” ) {            # Add leading zeros to the zone number if it is specified
$zone = sprintf(“%03d”,$zone);
}

$command = $function.$zone.’00′;        # Add the “future” 00 string
$commandlen = 2 + strlen($command);     # Calculate the length of the command
$commandlen = strtoupper(dechex($commandlen));
if ( strlen($commandlen) == 1) {
$commandlen = ’0′.$commandlen;  # Add a leading zero if required
}
$command = $commandlen.$command;        # Compile the whole command

$chksumasc = 0;

# Add all the Ascii values together
$array = str_split($command);
foreach($array as $char) {
$chksumasc = $chksumasc + ord($char);
}

# Calculate the Mod-256 of the total values
$chksum = bcmod($chksumasc,256);

# Subtract that from 256 to generate the checksum
$chksum = strtoupper(dechex(256-$chksum));

if ($usesecure) {               # If we are securly connecting to the panel prepend the address
$ness = “ssl://$ness”;
}

echo “Connecting to $ness:$nessport\nSending: $command$chksum\n”;

$fp = fsockopen($ness, $nessport, $errno, $errstr, 30); # Open the TCP connection to the panel
if (!$fp) {
echo “$errstr ($errno)<br />\n”;
} else {
$out = $command.$chksum.”\r\n”;
fwrite($fp, $out);
if (!feof($fp)) {
echo fgets($fp, 128);
}
fclose($fp);
}

?>

Those who share get better loving:
  • Digg
  • Twitter
  • Facebook
  • del.icio.us
  • Google Bookmarks

Leave a Comment

You must be logged in to post a comment.


No Clean Feed - Stop Internet Censorship in Australia