A suitably nerdy April Fools’ prank
It wasn’t until this morning that it sank in that today was April Fools’ Day. Unfortunately, I didn’t have enough time to come up with anything suitably inventive to trick you, the readers. But I did come up with some stuff to do at work. We mostly use HP LaserJet printers here, and if you’ve been keeping up on idle pranking news, you know that the ready message can easily be modified through the use of a simple Perl script. How could I resist?
This first program takes the IP address of a printer to target and a file name. Each line of the file is displayed on the printer’s display for two seconds, then it loops back around when it reaches the end. Naturally, I used this script to display the lyrics to Rick Astley’s “Never Gonna Give You Up” on the printer in continuous loop, thus Rick’Rolling anyone who walked past the printer, noticed the blinking messages, and stopped to investigate. Just keep in mind the limitations of your printer’s display; this one has two rows of twenty characters each, which is just enough for the longest lyric in the song. Any extra characters get chopped off.
#!/usr/bin/perl
use strict;
use warnings;
use IO::Socket;
unless (@ARGV) { print "usage: $0 <ip address> <file name>\n" ; exit }
if ($ARGV[3]) { print "Too many args\n" ; exit }
my $peeraddr = $ARGV[0];
my $filename = $ARGV[1];
my @text;
open(FILE_INPUT, "<$filename");
while (<FILE_INPUT>) {
chomp $_;
push(@text, $_);
}
my $i = 0;
my $curtext;
while (1) {
$curtext = $text[$i];
$i++;
$i = 0 if ($i > $#text);
my $socket = IO::Socket::INET->new(
PeerAddr => $peeraddr,
PeerPort => "9100",
Proto => "tcp",
Type => SOCK_STREAM
) or die "Could not create socket: $!";
my $data = <<EOJ
\e%-12345X\@PJL JOB
\@PJL RDYMSG DISPLAY="$curtext"
\@PJL EOJ
\e%-12345X
EOJ
;
print $socket $data;
sleep 2;
}
This second script is slightly more complicated. The basic premise is that SkyNet is about to be awakened, and a countdown timer is displayed on all of the HP printers in the office (we have three). Then, when SkyNet is awakened, the printers display “MISSION: Find Sarah Connor”. The script is complicated by the fact that we have HP printers of different models, two of which can display 16 characters per row and one of which can do 20. So I had to generate messages of different length for the various printers. We have one guy here at work who is legitimately afraid of the rise of SkyNet, so this might have spooked him, but unfortunately he wasn’t in today.
#!/usr/bin/perl
use strict;
use warnings;
use IO::Socket;
use Date::Manip;
my %ips = ('10.1.0.20'=>16, '10.1.0.21'=>16, '10.1.0.22'=>20);
my $target = &ParseDate('2008-04-01T16:01');
my $rdymsg20;
my $rdymsg16;
my $keepRunning = 1;
while ($keepRunning) {
my $now = &ParseDate("now");
if (&Date_Cmp($now, $target) < 0) {
my $delta = &DateCalc($now, $target);
my $hr = &Delta_Format($delta, 0, "%hv");
my $mn = &Delta_Format($delta, 0, "%mv");
my $hrmn = &Delta_Format($delta, 0, "%hv:%mv");
$rdymsg20 = "SykNet will awaken in $hr hrs and $mn mins";
$rdymsg16 = "SkyNet is coming in $hrmn ";
} else {
# 1234567890123456789012345678901234567890
$rdymsg20 = " MISSION: Find Sarah Connor ";
$rdymsg16 = " MISSION: Find Sarah Connor ";
$keepRunning = 0;
}
my $touse;
foreach my $peeraddr (keys %ips) {
my $socket = IO::Socket::INET->new(
PeerAddr => $peeraddr,
PeerPort => "9100",
Proto => "tcp",
Type => SOCK_STREAM
) or die "Could not create socket: $!";
if ($ips{$peeraddr} == 16) {
$touse = $rdymsg16;
} elsif ($ips{$peeraddr} == 20) {
$touse = $rdymsg20;
}
my $data = <<EOJ
\e%-12345X\@PJL JOB
\@PJL RDYMSG DISPLAY="$touse"
\@PJL EOJ
\e%-12345X
EOJ
;
print $socket $data;
}
sleep 10;
}
I also set the message on one of the printers to “Help, I’m a slave in a printer factory!”
So, what did you do for April Fools’?
April 2nd, 2008 at 15:25
We have two printers on my floor; the newer one says “I’m fancy”. The older one says, “Look at the new guy”.
But my contribution for April Fools Day was a bit of creative writing. It seemed well-received.