This article is from a FAQ concerning SCO operating systems. While some of the information may be applicable to any OS, or any Unix or Linux OS, it may be specific to SCO Xenix, Open Desktop or Openserver.

There is lots of Linux, Mac OS X and general Unix info elsewhere on this site: Search this site is the best way to find anything.

Printing FAQ

Where do I get "netcat" and how do I use it?

This is about printing to network printers, specifically HP network printers and other print servers that use a direct "raw" network port.


Hate these ads?

(I want to thank Jack Wendel for many suggestions that hopefully have made this section easier to understand)

There's a lot of information here. It's all simple, it's all step by step, but you need to READ it. Don't just skim through this and start typing away without any understanding. READ.

Brian White has a more prepackaged version: Bofcusm/2661.html http://www.aljex.com/bkw/sco/#rlpnc

The netcat we are talking about here is described at /KevinSmith/netcat/. There is another more widely known netcat ("nc") written by Hobbit that is used (among other things) for port scanning.

Netcat "cats" to the network. Most network printers work that way at some port number. For example, HP printers use port 9100. So if you open up port 9100 (a simple "telnet deviceip 9100" is all it takes), anything that is presented there will be printed. With netcat, all you need is a hostname or a raw ip address and the proper port number. Anything you send will be printed- it's that simple. Just like you "cat" a file to the screen, "netcat" sends it to an ipaddress and a port (though unlike "cat", netcat is a filter- you pipe data TO it).

See Buggy Netgear Printservers if you have Netgear






Why use netcat? Because it works. Time after time I've fixed nasty and confusing network printer problems by just using netcat instead of the HP printing method or even lpd. Netcat works. The HP printer stuff and lpd include all sorts of overhead you just do not need.

(Some network print servers do not work in this simple manner. Some will use more complex protocols such as LPD. You may be interested in /Unixart/netcatlpr.html if you have a print server like that.)

Download netcat from the link above or, if you don't want the C program source and don't need a COFF binary, use one of these ELF binaries (if you don't understand any of that, you probably want the ELF). Get netcat.sco5.newer if you have Openserver 5.0.4 or better or Unixware, netcat.sco5.older if you have 5.0.0 or 5.0.2, and netcat.v42 if you have 3.2v4.2. Put it somwhere in your PATH and rename it "netcat".

Quickest instructions:

Choose an interface script from /usr/spool/lp/model. That's often HPLaserJet or "dumb". Copy that script somewhere that lp can read it: /usr/spool/lp/admins/lp/interfaces/model.orig is a good choice. If you already had used the HP Printer Manager to create a printer, your script is already there. Do a chmod 755 on it just in case. Then create this in /usr/spool/lp/model, calling it whatever you will ultimately call your printer: I'll assume MYPRINTER here:

# /usr/spool/lp/model/MYPRINTER
/usr/spool/lp/admins/lp/interfaces/model.orig/MYPRINTER   "$@" | netcat -h ipaddress -p 9100

Then:

/usr/lib/lpadmin -p MYPRINTER -m MYPRINTER -v /dev/null
# That creates /usr/spool/lp/admins/lp/interfaces/MYPRINTER
/usr/lib/accept MYPRINTER
enable MYPRINTER

That's it. Read the rest only if you need to understand better.

Here's another way to create an HP printer named MYPRINTER that works on port 9100. This assumes OSR5. You should substitute MYPRINTER with whatever you want to call your printer in all steps below. DON'T USE THIS IF YOUR PRINTER ISN'T AN HP LASER OR COMPATIBLE. If you have a dotmatrix or thermal printer or anything NOT HP, skip this and use the other netcat scripts.

Download ftp://ftp.aplawrence.com/pub/netcat/netcat.hp.model

Download the netcat binary. We'll assume it was netcat.sco5.newer above and that you are sitting in the directory you downloaded these too..

You need to edit the interface script. If you don't know how to use vi, see Vi Basics.



# create model for lpadmin to use
cp  ./netcat.hp.model /usr/spool/lp/model/MYPRINTER
# put netcat in /usr/bin
cp ./netcat.sco5.newer /usr/bin/netcat
# make it executable
chmod 755 /usr/bin/netcat
# make sure model.orig is there (it may already exist)
mkdir /usr/spool/lp/admins/lp/interfaces/model.orig
# put MYPRINTER in model.orig.  
cp /usr/spool/lp/model/HPLaserJet /usr/spool/lp/admins/lp/interfaces/model.orig/MYPRINTER
chmod 755 usr/spool/lp/admins/lp/interfaces/model.orig/MYPRINTER
# vi /usr/spool/lp/model/MYPRINTER and point
# MYPRINTER where it needs to go.  Change this line: YOUR_PRINTER_OR_IP="192.168.2.4"
vi /usr/spool/lp/model/MYPRINTER 
# now create the printer
/usr/lib/lpadmin -p MYPRINTER -m MYPRINTER -v /dev/null
# That creates /usr/spool/lp/admins/lp/interfaces/MYPRINTER
# now finish up
/usr/lib/accept MYPRINTER
enable MYPRINTER


cartoon
My Unix and Linux Troubleshooting E-Book will show you how to
solve tough system problems!

You can get that script here: ftp://ftp.aplawrence.com/pub/netcatscript. Be sure to READ IT and edit it as necessary!

You can test netcat from the command line:



date | netcat -h ip_address -p 9100
echo ^L | netcat -h ip_address -p 9100


Many of you don't need to read any more. Nothing else is necessary if you are printing as that assumes. If not, read on:

A simple netcat interface script is:



PORT=9100 # for hp, netgear, some others
shift; shift; shift; shift; shift
# The lpsched program sends 5 arguments that we are going to ignore.
# arguments 6 and on are the file names to be printed
# We just throw away everything but the file names by using shift 5 times
# arguments 6 through whatever are now $*
cat $* | netcat -h printserver -p $PORT
# If you need lfcr translation, do:
# cat $* | /usr/lib/lponlcr | netcat -h printserver -p $PORT
# If you need a pagefeed, do:
# cat $* /usr/lib/Control_L | /usr/lib/lponlcr | netcat -h printserver -p $PORT
# sleep 15
# if you have truble with multiple jobs, try uncommenting sleep
# note that's a printer problem, not a netcat issue


To create /usr/lib/Control_L, do:



echo -n ^L  > /usr/lib/Control_L
# type Ctrl-L 


You really need to TYPE Cntrl-L (hold CTRL and press L). When you do that your screen will blank. Just keep going with the ">" etc.

You'd save that as "netcat" in /usr/spool/lp/model. When you create your printer, use that as the interface script (it will appear in your list of choices). What I do is copy it to the name I will use for the printer, modify the copy to use the correct host name or ip address and port number, and then my printers use the same name for their scripts: printer "officehp" uses the interface script "officehp" etc.

You don't have to use the printer configuration manager to add a simple printer. For example, to add a printer called "printer" after modifying the script as above:



/usr/lib/lpadmin -p printer -m netcat -v /dev/null
# MUST have /usr/spool/lp/model/netcat script !!
# If script were called "hpprinter" you'd do:
# /usr/lib/lpadmin -p printer -m hpprinter -v /dev/null
# then:
/usr/lib/accept printer
enable printer


Here's another example that uses an ip address on an Intel Netport port 2:



PORT=3002
shift; shift; shift; shift; shift
cat $* | netcat -h 192.168.2.9 -p $PORT


And here's a Netgear PS110 on port one:



shift; shift; shift; shift; shift
cat $* | netcat -h netgear.wherever.com -p 4010


Remember, these are interface scripts you will use when you define a printer.

If your application lets you specify a printer command (RealWorld, Mas90/Mas200 and many more), you can use netcat directly. For example, you might have previously put something like this in a configuration file:



LP1=">lp -dmyprinter %s";export LP1


(This is the way Realworld configures printers; it's not necessary for you to understand this)

You'd replace this with:



LP1=">netcat -h printerip -p 9100";export LP1


If the "printerip" is the address you can "ping" and 9100 is the port number used for printing.

There are other examples here. These are more complex examples that may require some experience to use and understand.

Printing through pipe device

Printing through interface script

You'll also want to see /Jeffl/portnumbers.html to find out what port numbers to use with your network printer or printserver. IF YOU USE THE WRONG PORT NUMBER IT WON'T WORK.

The netcat program can also help diagnose problems. The folowing was taken from a newsgroup posting by Kevin Smith (the author of this netcat):

(You don't need to read or understand any of this to use netcat)



 


 
 $ netcat -d 999 -h hp3 -p 9102


 
 debugl = 999
 hostname = hp3
 port = 9102
 gethostbyname()=0x404340
 socket()=3
 sin.sin_addr.s_addr=0x2882b8d0
 connect()=-1
 Connect to port 9102 on hp3: Connection refused


 


 
 Explanation:


 
 debugl = 999


 
     Your debug level.  Anything >= 1 triggers debug messages.
     There are no "levels", just on and off.


 
 hostname = hp3


 
     Value from -h arg


 
 port = 9102


 
     Value from -p arg


 
 gethostbyname()=0x404340


 
     Return value of gethostbyname() which is the address of the
     hostent struct which is useless unless it's 0 which means there
     was an error.


 
     This translates the host name (hp3) into an ip address.


 
 socket()=3


 
     Return value of the socket() call.  It's really a file descriptor
     for the network connection.  Not too many reasons for this to fail.
     Useless unless it's -1.  Should always be 3 (stdin = 0, stdout = 1,
     stderr = 2, 3 is next).


 
     This is the first half of opening a network connection.


 
 sin.sin_addr.s_addr=0x2882b8d0


 
     The ip address in hex, as found by gethostbyname(), not adjusted
     for network byte order.


 
     0x2882b8d0 -> 0x28.0x82.0xb8.0xd0 -> 40.130.184.208 -> 208.184.130.40


 
     I should be using inet_ntoa() to show the ip.


 
 connect()=-1


 
     The return from the connect() call.  Who knows why this was
     failing for the coff and not the elf versions.  I run a coff
     version on OSR 5.0.0 (compiled on OSR 5.x though).


 
     This is the second half of opening a network connection, where the
     target host is actually contacted and the connection is established.


 
 Connect to port 9102 on hp3: Connection refused


 
     Output of


 
         perror("Connect to port <port> on <host>")


 


 


If you have Perl, netcat is very simple:



#!/usr/bin/perl
use IO::Socket;
$host=shift @ARGV;
$port=shift @ARGV;
$socket=IO::Socket::INET->new(PeerAddr=> $host, PeerPort=> $port, Proto=> 'tcp',
Type=> SOCK_STREAM) or die "Can't talk to $host at $port";



while (<>) {
print $socket $_;
}
close $socket;


If you use this, don't use -h and -p, just give the host first.

Copy that to /usr/bin/netcat or anywhere else you like (somewhere in your PATH is a good idea).

Another netcat how-to: http://www.tkrh.demon.co.uk/netcat.html









-
Google Friend Connect users can
comment on this page here


Enter your email address for automatic notification of new posts here
(be sure to whitelist 'feedburner.com' if you use spam filtering)

Or use any RSS reader

Delivered by FeedBurner


Views for this page
Today This Week This Month This Year  Overall
282698,206 20,421

Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more. We appreciate comments and article submissions.

Publishing your articles here

pavatar.jpg
More:
       - Networking
       - Printing
       - FAQ




Unix/Linux Consultants


http://echo3.net/ Unix/Linux Custom Applications, Web Hosting, C/C++ Programming Courses


http://thatitguy.com Business networking servers, Linux and Unix experts. In business since 1997! Windows and Exchange to Samba and Scalix migration experts.


http://bcstechnology.net Full service Linux & UNIX systems integrator; Windows to UNIX/Linux Client-Server Specialist; Secure E-Mail & Website Hosting; Thoroughbred Software Developer; Custom Industrial Automation; Hardware & Electronics Experts; In Business Since 1985.



Twitter
  • Dec 3 14:01
    Just went out and added more bungee reinforcement. That ought to hold it..
  • Dec 3 13:58
    I'm second guessing myself on how I bungeed the cover on my golf cart for winter storage. Wondering if high wind could rip it off..




card_image








Change Congress