Skip to content

Instantly share code, notes, and snippets.

@natmchugh
Created August 15, 2013 14:15
Show Gist options
  • Save natmchugh/6241140 to your computer and use it in GitHub Desktop.
Save natmchugh/6241140 to your computer and use it in GitHub Desktop.
<?php
function changeMessage($ip, $msg)
{
$fp = fsockopen($ip, 9100, $errno, $errstr, 5);
if (!$fp) {
echo "$errstr ($errno)";
} else {
$string = "\x1B%-12345X@PJL RDYMSG DISPLAY = \"".$msg."\"\r\n\x1B%-12345X\r\n";
fwrite($fp, $string);
echo "Sent " . $string . " to " . $ip . ".".PHP_EOL;
flush();
fclose($fp);
}
}
function getMessage($ip)
{
$fp = fsockopen($ip, 9100, $errno, $errstr, 5);
if (!$fp) {
echo "Possibly offline.";
} else {
fwrite($fp, "\x1B%-12345X@PJL INFO STATUS\r\n\x1B%-12345X\r\n");
$term = false;
while (!feof($fp) && !$term)
{
$string = fgets($fp, 128);
echo str_replace("n","",$string);
flush();
if (!(strpos($string, "ONLINE") === false))
{
$term = true;
}
}
fclose($fp);
}
}
getMessage("10.3.10.11");
echo '<br/>';
changeMessage("10.3.10.11", strtoupper('billing failed'));
echo '<br/>';
getMessage("10.3.10.11");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment