[Home]

Printing with Netcat.

Netcat is a utility to allow to to bypass the various network printing utilities supplied by third parties and that come with the O.S. It allows you to print directly to a specific port on a specific IP address.

The best use of netcat is within the printer interface scripts. Use one of the existing scripts and pipe the information directly into netcat. Sample scripts are given later on.

When first installed, try a few tests from the command line before adding in other variables:

The basic format is:

cat filename | netcat -h hostname -p portnumber

Where

  • hostname is the NAME of the host as returned by DNS or from /etc/hosts. It is NOT the name of the printer.
  • portnumber, this is the port on the print server you want to print to.
  • For example:

    cat /etc/passwd | /usr/lib/lponlcr | netcat -h hpex3acc -p 9100

    You may need to first pipe the output via the filter lponlcr to add in a CR. This depends on the print server and the print job. Adjust as required.

    For a copy of the source and pre-compiled SCO binaries please visit http://www.LearnByDestroying.com/sco/lp/

    Port Numbers

    For a full list please visit http://www.LearnByDestroying.com/sco/lp/printservers.htm

    Sample Model Files for SCO OpenServer

    One way to handle specifing the Host name and port number is to embed them at the top of your script and then call them later on e.g.

    IPADD="hplaser"   # Set this to the name/IP address of server
    PORT="9100"     # Port number on print server
    
    [snip]
    
    | /usr/lib/lponlcr |
    /usr/local/bin/netcat -h $IPADD -p $PORT 
    

    This will work but from an administration point of view it is messy.

    A better solution is to centralise all the Host/Port numbers in one location (you can also use this method for printing to VisionFS printers) and have one printer model file for all.

    This is the same example as above except is looks at the file /etc/printers for all the information.

    # Look for HOST and Port address
    # Note that names and ports are in the file /etc/printers
    # in the format:
    #	printer_name:host_name:port_number
    
    PRTSETUP=`grep "^$printer:" /etc/printers`
    if [ $? = 0 ]
    then
    PRTHOST=`echo $PRTSETUP|awk -F: '{ print $2 }'`
    PRTPORT=`echo $PRTSETUP|awk -F: '{ print $3 }'`
    else
     exit 1
    fi
    
    [snip]
    
    | /usr/lib/lponlcr |
    /usr/local/bin/netcat -h $PRTHOST -p $PRTPORT
    

    Installing the interface files

    Copy one of the example interface files into the lp model directory (/usr/spool/lp/model) and then:

    Local Interface Scripts

    Configuring different devices to use netcat


    Comments and suggestions always welcome - tom@tkrh.demon.co.uk