blog home »

trees.pl

plain text source
hide syntax highlighting
hide line numbers


1    #!/usr/bin/perl
2   
3     
4      # Remember... These Come from Trees
5      # This program accepts the IP address or hostname of an HP
6      # or compatible printer on the command line and uses HPPJL
7      # to set the "Ready Message" to "Remember... These Come From Trees"
8      # reminding people not to waste paper.  Please visit:
9      #
10     #    http://thesecomefromtrees.blogspot.com/
11     #
12     # for more information.
13     #
14     #
15     # THIS PROGRAM IS PROVIDED WITH NO WARRANTY OF ANY KIND EXPRESSED OR IMPLIED
16     # THE AUTHOR CANNOT BE RESPONSIBLE FOR THE EFFECTS OF THIS PROGRAM
17     # IF YOU ARE UNCERTAIN ABOUT THE ADVISABILITY OF USING IT, DO NOT!
18     #
19     # Yaakov (http://kovaya.com/)
20  
21   use strict;
22   use warnings;
23  
24   unless (@ARGV) { print "usage: $0 <ip address> or $0 <hostname>\n" ; exit }
25  
26   my $target = $ARGV[0];
27   chomp $target;
28   my $peeraddr;
29  
30   if ($target =~ /\w/) {
31     my $ip = gethostbyname($targetor die "Can't resolve address: $!";
32     $peeraddr = inet_ntoa($ip);
33   else {
34     $peeraddr = $target
35   }
36  
37   use IO::Socket;
38   my $socket = IO::Socket::INET->new(
39       PeerAddr  => $peeraddr,
40       PeerPort  => "9100",
41       Proto     => "tcp",
42       Type      => SOCK_STREAM
43       ) or die "Could not create socket: $! (Maybe the address you used is bad?)";
44  
45   my $data = <<EOJ
46   \e%-12345X\@PJL JOB
47   \@PJL RDYMSG DISPLAY="Remember... These Come From Trees"
48   \@PJL EOJ
49   \e%-12345X
50   EOJ
51   ;
52  
53   print $socket $data;
54   print "\"Remember... These Come from Trees\" sent to $target";
55   if ($peeraddr ne $target) {print " ($peeraddr)";}
56   print "\n";