Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

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.


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);
        my $len = length $printer{$key};
        unless(syswrite($sock, $printer{$key}. chr(27), $len) == $len)
+ {
            print "Server unexpectedly closed connection\n";
HP site link 1

HP site link 2

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

Replies are listed 'Best First'.
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.


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
      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.


Log In?

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2023-12-06 07:55 GMT
Find Nodes?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?

    Results (30 votes). Check out past polls.