#! /usr/bin/perl -w # # cheese-on-hp.pl: put a message on the diplay of a HP LaserJet # # Adapted from a Pascal program by Grant Warkentin # # (C) 1999, Erik Mouw (J.A.K.Mouw@its.tudelft.nl) # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # use strict; use Socket; sub sendToPrinter ($$$) { my($printerName, $printerPort, $message) = @_; my($printerAddress,$proto,$addr); chop $message; $printerAddress = (gethostbyname($printerName))[4]; $addr = sockaddr_in($printerPort, $printerAddress); $proto = getprotobyname('tcp'); socket(S, AF_INET, SOCK_STREAM, $proto) or die $!; connect(S,$addr) or die $!; select S; $| = 1; select STDOUT; print S "\033%-12345X\@PJL RDYMSG DISPLAY =\"$message\"\n"; print S "\033%-12345X\n"; print "Message on display: \"$message\"\n"; close S; }; my ($printerName, $printerPort, $randomSeed, $index); $printerName = "$ARGV[0]"; $printerPort = $ARGV[1]; if (!$printerPort) { $printerPort = 9100; } if (!$printerName) { print "Usage: $0 printername [port] < file\n"; print "Example: $0 hplj.hp.com < cheeses.txt\n"; print " $0 hplj.hp.com 9101 < cheeses.txt\n"; print "Default port is $printerPort\n"; exit; } $randomSeed = time ^ $$ ^ unpack "%32L*", `ps aux | gzip`; srand($randomSeed); my ($message, @messages); @messages = (); $index = int(rand ( $#messages)); sendToPrinter($printerName, $printerPort, $messages[$index]); exit;