Oops, I missed the fact that your printer is not networked but connected through USB. That will make things more difficult.
Hmm... instead of nc (netcat), you'll need something that can communicate with the appropriate USB printer port device.
Once you have that, you could get the sequence that needs to be piped to the printer from my script.
Once you can get the answer from the printer, my script also has the commands that can be used to decode the serial number.
9100 is the port number for HP JetDirect network printer adapters (either built-in to many modern printers, or also available as external boxes). Basically, setting up a TCP connection to printer's port 9100 is almost a direct replacement for a parallel cable: all the communication with the actual printer should work just the same as with a traditional, parallel-connected printer. The USB printer device should work about the same.
Connecting to port 9100 does not work with most computers: instead of using port 9100, most computers use more complicated printer sharing protocols in different ports. The most common ones, in no particular order, are here:
- IPP in port 631/TCP (CUPS in Mac OS X and most Linuxes)
- traditional Unix print spooler protocol (LPD) in port 515/TCP (optional in CUPS, standard in LPRng and other older Unix/Linux print spoolers)
- Windows printer sharing protocol in port 445 (SMB-over-IP) and/or 135-139 (NetBIOS-over-TCP/IP)
All of those will require proper print job metadata and won't necessarily give you the raw response from the printer - you cannot just open two-way communications with the printer and pipe the commands/print jobs in, as you can do with JetDirect.
At the moment, I don't have any USB-connected printers I could test with. Perhaps someone else can help?
But if the printer is physically located near to you, how about the old-fashioned method of reading the serial number off the label at the back of the printer? Usually the label should contain the model/product number too.