root / pykota / trunk / contributed / pagecount.pl @ 3436

Revision 3259, 2.6 kB (checked in by jerome, 17 years ago)

Began work on moving from GNU GPL v2 or later to GNU GPL v3 or later.
TODO : Also move command line tools and library.
TODO : Change documentation from SGML DocBook? to XML DocBook? to
TODO : accomodate the GNU GPL v3 text available in DocBook? XML
TODO : from www.gnu.org

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
Line 
1#!/usr/bin/perl -U
2#
3# PyKota : Print Quotas for CUPS
4#
5# (c) 2003, 2004, 2005, 2006, 2007 Jerome Alet <alet@librelogiciel.com>
6# This program is free software: you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation, either version 3 of the License, or
9# (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program.  If not, see <http://www.gnu.org/licenses/>.
18#
19#
20############################################################
21#                                                          #
22# This script is 100% copyright (c) 2003 Ren�und Jensen  #
23#                                                          #
24# He contributed it to the PyKota project on Dec. 4th 2003 #
25# and licensed it under the terms of the GNU GPL.          #
26#                                                          #
27# MANY THANKS TO HIM                                       #
28#                                                          #
29############################################################
30#
31#
32# $Id$
33#
34#
35
36use Socket;
37use IO::Socket;
38
39if (@ARGV < 2){
40    print "usage: pagecount.pl servername port\n";
41}
42
43$printer = @ARGV[0];
44$port    = @ARGV[1];
45
46$ssh = osocket($printer, $port);
47if ($ssh){
48    $page = pagecount($ssh);
49    print $page."\n";
50    $ssh-close();
51    exit(0);
52}else {
53    exit(1);
54}
55
56sub pagecount {
57    my $sh = @_[0];    # Get sockethandle
58    # send pagequery to sockethandle
59    send($sh, "\033%-12345X\@PJL INFO PAGECOUNT\r\n",0);
60    # Read response from sockethandle
61    recv($sh,$RESPONSE,0xFFFFF,0);
62    (my $junk,$pc) = split (/\r\n/s,$RESPONSE); # Find the pagecount
63    $pc =~ s/(PAGECOUNT=)?([0-9]+)/$2/g;
64    return $pc;                                 # Return pagecount
65}
66
67
68sub osocket {
69
70 # Connecting to @_[0] = @arg[1] = $printer
71 # On port @_[1] = 9100 JetDirect port
72 # Using TCP protocol
73    my $sh= new IO::Socket::INET(PeerAddr => @_[0],
74                                 PeerPort => @_[1], 
75                                 Proto => 'tcp');
76    if (!defined($sh)) {        # Did we open the socket?
77        return undef;           # No! return undef
78    } else {                    # Yes!
79        $sh->sockopt(SO_KEEPALIVE,1);   # Set socket option SO_KEEPALIVE
80        return $sh;             # return sockethandle
81    }
82}
Note: See TracBrowser for help on using the browser.