Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

HP Jet Direct Control

by cacharbe (Curate)
on May 31, 2001 at 05:25 UTC ( #84430=snippet: print w/ replies, xml ) Need Help??

Description: This is code designed for controlling an HP printer using only IO::Socket, oh and interoffice war fare. I used it to "threaten" the global help desk. I told them that if I didn't get what I want (Access on a certain machine for a project that was two weeks past due because of their mess up) I'd make all of the printers at the world head quarters display $msg. *grin*

I know it's not pretty, but it works nicely for me

Update: I included a couple of the resources I used to figure out the PJL syntax and commands used in the script.

C-.

use IO::Socket;

my $host = 'INSERT IP HERE'; 
my $port = '9100'; #jet direct port
my $eoln = "\x0A";
$msg = 'Insert $0.25 and Press Go to Continue';

my $sock = IO::Socket::INET->new(PeerAddr => $host,
                                 PeerPort => $port,
                                 Proto => 'tcp');
die "Couldn't connect to $host on $port: $!\n" unless $sock;

print "Connected\n";
    $printer{"escapeseq"} = chr(27) . "%-12345X\@PJL";
    $printer{"input"} = "\@PJL OPMSG DISPLAY= \"$msg \" $eoln";
    $printer{"last"} = "\x1B&k3G";
    foreach $key (sort(keys %printer)){
    if ($key eq "escapeseq"){
        syswrite($sock, $printer{$key}, $len);
    }else{
        my $len = length $printer{$key};
        unless(syswrite($sock, $printer{$key}. chr(27), $len) == $len)
+ {
            $sock->close;
            print "Server unexpectedly closed connection\n";
            last;
        }
    }
}
HP site link 1

HP site link 2

and you can do a search on google for 12345x@pjl

Comment on HP Jet Direct Control
Download Code
Re: HP Jet Direct Control
by Desdinova (Friar) on Jun 15, 2001 at 01:51 UTC
    Neat little script. As side note this will only work with either single port jetdirect cards. the multiport units use a different TCP port for each printer connected to it. The ports are
    • Printer port 1 -- 9100
    • Printer port 2 -- 9101
    • Printer port 3 -- 9102
    A list of all the Ports used by the jet direct can be found here .
    If you wanted to be real mean you could have threatened to use the print test page codes
      Heh, Noted and added to the list of Mayhem
      **Cue Evil Laughter, fade up scary music and.....Blackout.

      C-.

Re: HP Jet Direct Control
by raven67 (Initiate) on Nov 27, 2001 at 04:00 UTC
    Just a thought : Add some nmap into it and sweep whole networks for jetdirects, then print to them. :P -- ravnx::EFNet ravnx@netpimpz.com
      That's a seperate piece, actually. Someone inside the company was kind enough to put a public database listing all the printer Q's out on the intranet, with a hardware desc which I can access with the code to determine if the printer has a jet direct port.

      I actually wrote code to do the map, but stumbled upon the database and retired the other code to my catacombs for future use.

      C-.

Back to Snippets Section

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: snippet [id://84430]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2014-07-26 10:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (175 votes), past polls