Intercepting data being sent to an Ethernet connected printer - Page 1
Forum section: electronics / projects

author: TopLoser
author_rank: Unknown
timestamp: May 28, 2018, 10:20:17 am
content: One of my beloved customers has a Zebra barcode printer that is connected to a Windows server via ethernet. It just prints A5 labels out on demand and a guy slaps the label onto a pallet. Easy.They need to automate the process and put the the data on the label onto a RFID tag embedded in the pallet. I can read/write the RFID tags ok, I just need to capture the existing data that gets sent to the printer. Plus I'd like to disconnect the existing printer entirely, it's not needed.So... is there a lovely simple device that has ethernet in and RS232 out? I can change the existing driver parameters on the server BUT I CAN'T install any new drivers. No using one of the hundreds of virtual COM port devices on the market. That would be far too simple and sensible so I'm not allowed to do it...Or do I need to resort to writing some software on my ancient DOS PC to pretend to be a printer? I've got a TCP stack and a sockets library I'm familiar with that I already use to access a web service on the server. Or stick a Pi or Arduino in the middle with some custom software?I've googled the hell out of this and I can't find anything helpful.

author: PA0PBZ
author_rank: Super Contributor
timestamp: May 28, 2018, 10:32:18 am
content: Did you check what emulation the printer is using? If it is GDI... good luck translating that back to ASCII...

author: TopLoser
author_rank: Unknown
timestamp: May 28, 2018, 10:38:28 am
content: No it's really simple - XML data.I wouldn't attempt converting bitmap data even i'm not that daft!

author: nali
author_rank: Frequent Contributor
timestamp: May 28, 2018, 10:48:57 am
content: Are you allowed to change printer queue settings? If so you can just set it as a standard TCP/IP port, set the IP address either to localhost if you can run software on the same machine, or the address of a RPi / whatever then listen on whatever port you choose.

author: Jeroen3
author_rank: Super Contributor
timestamp: May 28, 2018, 10:56:49 am
content: Yay, tech debt.I'd first port mirror the it and wireshark if you can at least understand any of the stuff being sent to the printer.If it's encrypted, or if it's talking some proprietary stuff you're out of luck already.

author: Marco
author_rank: Super Contributor
timestamp: May 28, 2018, 11:08:25 am
content: Quote from: TopLoser on May 28, 2018, 10:20:17 amIt would certainly give you job security ... few others will be able to maintain a DOS based printer relay and protocol analyzer. I'm going to guess that the most sane solution is entirely out of the question? In other words, just changing the program generating the labels. I don't understand why industry isn't more gung ho about open source. Paying so much money to just end up with a giant pile of fragile hacks.I'd get a single board computer with dual ethernet (up-board?) so you can capture and resend packets, sniffing runs the risk of missing stuff AFAICS. Use pcapplusplus to get in the middle if necessary, but presumably a simple program which analyzes/relays data coming in on a TCP/IP port will suffice.PS. I guess with a TCP based relay you don't really need the second ethernet connection either, only if you want to pass the raw packets.

author: TopLoser
author_rank: Unknown
timestamp: May 28, 2018, 11:28:10 am
content: Quote from: nali on May 28, 2018, 10:48:57 amYes I can add a standard TCP/IP port and assign the driver to it. I can also select the 'Print directly to device' option which makes the port status always 'READY', does not show 'OFFLINE' even when the printer is disconnected. Which looks promising.If I then try cheating and print a test label to one of the off the shelf 'Ethernet/RS232' devices WITHOUT the virtual COM port software installed I do actually get some printer specific header data dumped out of the serial port, just missing all the important useful data for some reason!

author: TopLoser
author_rank: Unknown
timestamp: May 28, 2018, 11:31:17 am
content: Quote from: Marco on May 28, 2018, 11:08:25 amI don't want job security, I'm retired and just doing this as a favour!They use the same SAP based system across dozens of factories, no chance of modifying anything just a accommodate a single factory specific printer. I have to fall in line with what's already in place.

author: TopLoser
author_rank: Unknown
timestamp: May 28, 2018, 11:33:09 am
content: Quote from: Jeroen3 on May 28, 2018, 10:56:49 amNo it's not encypted in any way. I can install the same driver on my office PC and print the same label data to a USB serial port instead of a TCP port and the data coming out of the serial port is perfectly usable.

author: capt bullshot
author_rank: Super Contributor
timestamp: May 28, 2018, 11:43:48 am
content: Quote from: TopLoser on May 28, 2018, 11:31:17 amI do perfectly understand that kind of favour. Been there, done that (not on SAP but other strange systems) in various ways at various places (some of them I never heard from again, luckily). And I'd recommend against doing it that way. The correct way for the customer would be to ask the SAP consultants to set up this kind of workflow the SAP way (which would be very expensive to the customer). Your way will be way much cheaper and will work in the first place, but it'll come back and bite you for every change they have to make to their SAP system. As your favour isn't implemented the SAP way, the highly paid SAP consultants will refuse to touch it, maybe even force your customer to remove this "alien" from the SAP system for them to be able to maintain the system.So, yes it'll be a nice favour in short term, but a major PITA long term for the customer.

author: Marco
author_rank: Super Contributor
timestamp: May 28, 2018, 11:58:31 am
content: Just make sure everyone knows to hide it from the SAP vampires.A little Python based TCP/IP relay on a SBC should be simple enough to maintain even for someone else and not take too many hours to create, all your out if they complain about it is that little time you put. You'll almost certainly have a solution up and running an order of magnitude faster than they'll manage too.

author: TopLoser
author_rank: Unknown
timestamp: May 28, 2018, 12:05:22 pm
content: Quote from: capt bullshot on May 28, 2018, 11:43:48 amI understand that, but they've actually been sensible and started buying printers and other connected devices that accept XML formatted data to ease the process of changing in the future.I just need to get hold of that data, not change the workflow. Easiest way would be for them to install the virtual COM port driver on their server and print to that instead of the existing TCP port, but some things are 'challenging' to get approved...It's also one of the reasons I'd like an off the shelf solution, not some cobbled together bodge with smoke and mirrors.

author: bob225
author_rank: Frequent Contributor
timestamp: May 28, 2018, 12:12:53 pm
content: what about using a off the shelf print server/ethernet to serial device- most do bi-directional controleg.https://www.usriot.com/products/rs232-to-ethernet-converter.htmlhttps://www.usriot.com/products/serial-device-servers/

author: TopLoser
author_rank: Unknown
timestamp: May 28, 2018, 12:18:15 pm
content: Quote from: bob225 on May 28, 2018, 12:12:53 pmYes, they would be great - I mentioned those in my original post. BUT unfortunately they need virtual COM port drivers installed on the server PC to enable the full functionality and that's not allowed.I have a collection of them on my desk already... (including the one you linked to!)

author: bob225
author_rank: Frequent Contributor
timestamp: May 28, 2018, 12:32:32 pm
content: I take it the printer is network based ? or is installed locally ? if its network based is it on a fixed ip or dhcp ?setup a pc, spoof the ip and mac of the printer and sniff the ip packets ?edit. you should be able to config the adapter with a direct ethernet connection and set up a server tcp/udp server or client, the network/server should see it as network device, then theres no need for any vcom drivers

author: nali
author_rank: Frequent Contributor
timestamp: May 28, 2018, 12:55:28 pm
content: Quote from: TopLoser on May 28, 2018, 11:28:10 amHmm... assuming this is a Windoze machine you might want to look at the print processor (spooler) too, it'll be somewhere in the printer's advanced properties. Some vendors supply their own which may be messing things up. The native one is Winprint / RAW.Do you specifically need to pipe the print data to RS232? I thought you just needed to capture it for your RFID process.I've got one of those Ethernet>Serial devices at work somewhere (a different model to you though). You can telnet directly to a TCP port although IIRC it mangles CR/LFs for some reason.

author: bob225
author_rank: Frequent Contributor
timestamp: May 28, 2018, 01:00:03 pm
content: See my edit above, its been a while since I use anything serial base across ethernetedit. a quick look at the manual shows you can change its boot mode

author: JohnnyMalaria
author_rank: Super Contributor
timestamp: May 28, 2018, 01:00:15 pm
content: Might these help?Programming Guide - ZPL II ZBI 2 Set-Get-Do Mirror WMLZebra XML-Enabled Printer Reference Guide(Looks horrific)

author: TopLoser
author_rank: Unknown
timestamp: May 28, 2018, 01:10:41 pm
content: Quote from: JohnnyMalaria on May 28, 2018, 01:00:15 pmWell said. Bring back the good old days...

author: capt bullshot
author_rank: Super Contributor
timestamp: May 28, 2018, 01:55:53 pm
content: Quote from: TopLoser on May 28, 2018, 11:28:10 amAs far as I understand you, the printer driver starts to send data to the printer over Ethernet, but then expects some response from the printer to continue. The printer itself is connected by ethernet? JohnnyMalaria posted some manual which I didn't read, maybe the right answer is within these. So you'd want to set up a Raspi or whatever to listen on the correct port and IP address, and then emulate the printer side of the protocol?Did you catch the traffic between the server / printer driver and the actual printer using tcpdump or the like? You should see then whats happening. Next step would be to setup some simple scripting on a Raspi and give the driver the expected responses - even a simple replay of the data you captured with tcpdump may work.Don't say, I didn't warn you - see my post above.

author: TopLoser
author_rank: Unknown
timestamp: May 28, 2018, 02:48:10 pm
content: Quote from: capt bullshot on May 28, 2018, 01:55:53 pmAll very sensible advice, and you may be correct in thinking that the driver is expecting some kind of response after the inital header instead of blindly dumping the data. That's a good point. There aren't any errors generated on the PC though, it thinks it's printed everything ok.Unfortunately I don't have one of the printers and the customer is in Valencia in Spain...I'll have a look at the manuals but I think I'll end up saying NO to them. They can install the correct virtual COM port drivers for the off the shelf box, or pay the SAP vultures...

author: C
author_rank: Super Contributor
timestamp: May 28, 2018, 09:38:33 pm
content: Edit made more readableJust get a Raspberry PI & a USB to RS232 cable.The Raspberry becomes a windows network printer by loading the samba software. Standard windows drivers used.Samba software creates network interface for windows computers for network disks & printers..You create a Simba network printer share in config.You can then have options of print to file or print to com port.WEBMINIF you are new to samba or linux then you might want to load this.This makes Simba config real easy.via the web admin interface.C

author: nctnico
author_rank: Super Contributor
timestamp: May 28, 2018, 10:36:23 pm
content: Quote from: TopLoser on May 28, 2018, 12:05:22 pmIn the past I've designed & sold RS232 printer converter boxes for these kind of jobs to a major telecom operator. For the end customer these where off-the-shelve units. I guess a similar solution with ethernet interfaces would be suitable.

author: thermistor-guy
author_rank: Frequent Contributor
timestamp: May 29, 2018, 12:52:03 am
content: Quote from: TopLoser on May 28, 2018, 10:20:17 amI use Wiznet 110SR to connect my LAN to RS232-based test gear:http://www.wiznet.io/product-item/wiz110sr/RS Components has them. I bought mine from Saelig (US).One potential gotcha - check if you need hardware flow control on the RS232 and what type. The 110SR supports RTS/CTS, but not DSR/DTR, as per page 6 of the manual:http://www.wiznet.io/wp-content/uploads/wiznethome/S2E%20Module/WIZ100-105-110SR/Document/WIZ110SR_UM_v210e.pdfAprt from that, it works pretty well.

author: TopLoser
author_rank: Unknown
timestamp: May 29, 2018, 07:35:41 am
content: Yes but the Wiznet device is yet another that requires the virtual serial port driver installed on the server. Can’t do that.Wouldn’t buy it anyway because of the licensing rubbish for the driver:“If you agree with the End User License Agreement for WIZVSP, you will be able to download the program and get a registration key. When registering the product with license agreement, the MAC address of the product in use and the email address of the contact person are required.”Driver tied to the MAC address of the device? What happens when the thing fails and the end user has to replace it? Bit of an extra pain, none of the other devices are that fussy.

author: Marco
author_rank: Super Contributor
timestamp: May 29, 2018, 03:54:13 pm
content: A simple TCP/IP bidirectional proxy in python is like 10 lines of code, add some regular expressions to fish out the data aand pipe them to the RFID writer and you're done.

author: darrylp
author_rank: Regular Contributor
timestamp: May 29, 2018, 04:31:44 pm
content: Put the printer into dump mode, it will print out what is being sent to it. If it's ZPL a form of EPL the programming manuals will help you read and understand it. It's a very simple text based command language.Sent from my HTC One using Tapatalk 2

author: TopLoser
author_rank: Unknown
timestamp: May 29, 2018, 07:13:31 pm
content: Thanks but I know exactly what data is being sent to the printer and how to interpret it. I just want to remove the printer and capture that data. It’s the transfer mechanism that’s causing me grief not the data.Reduce the problem to it’s basics - capturing a plain text document sent using Notepad and using the Windows ‘Generic text’ printer driver to an ethernet port.

author: ThaHandy
author_rank: Newbie
timestamp: May 29, 2018, 10:08:34 pm
content: What about add a new local port and save it to afile.Next thing is to process the file at every print and relay it.

author: rstofer
author_rank: Super Contributor
timestamp: May 29, 2018, 10:29:12 pm
content: If you have an Ethernet HUB (switch won't work), plug it in just ahead of the printer. Now your normal TCP/IP goes into the hub and on to the printer, just like normal. But the traffic also comes out every other port so just hang a PC running Wireshark on the hub and get creative with the filtering if necessary.I would expect the upstream switch to limit traffic on the link to the hub as being either broadcast or address specific. You can filter out the broadcast stuff in Wireshark if it is a PITA.When I was writing code to emulate a plotter by mashing up step commands into HPGL sentences, the first thing I did was aim the traffic at a Linux box with an open port. I wrote a little piece of Berkeley Sockets code to listen on the port and copy the traffic to disc. This really expedited getting the sentences correct. However, I never expected to have to reply.I don't know what that possible reply stuff is about but you'll see it with Wireshark. Look for the packets with the source address of the printer and the destination address of the host sending the stream.

author: thermistor-guy
author_rank: Frequent Contributor
timestamp: May 30, 2018, 12:39:01 am
content: Quote from: TopLoser on May 29, 2018, 07:35:41 amYou need to use some s/w to configure the device, but once configured the device is stand-alone. I haven't needed to use or get a registration key.

author: C
author_rank: Super Contributor
timestamp: May 30, 2018, 12:59:03 am
content: TopLoserYou want simple, do not make it hard.You stateQuoteThat is a network printer.And you stateQuoteYour Windows server can use a network printer share, this needs no special software.You can do a test with a test windows computer to prove following works.On Test windows computer do following.1. connect a USB to RS232 cable. The Cable creates a COM port.2. Connect RFID thing to RS232 connector.3. make this a printer by adding a printer using com-port from #1.4. Share this printer. this creates a Ethernet connection to printer.You now haveComputer_namePrinter_Share_nameUsername & passwordthis Printer_Share_name should show in network neighborhood.When test computer is connected to customers network,Printer_Share_name should show on servers network neighborhood.On server, If you right click on printer share name and connect you get this RFID printer on server.Server should now be able to print to RFID.This should work.now the test windows computer could be any windows computer.Oryou could use any linux computer, even a raspberry PiSo a linux computer can replace the test windows computer above. look at previous post for linux.You have option if needed to have test or linux computer to send input from server to a file and have a program read that file and send it to RS232 if you need to change what is sent from server.Now the final step on server ischanging the program to use RFID printer instead of Zebra printer.OrChanging Zebra printer properties to match RFID printer.Now to sum it upNo added software on windows server. It is all standard windows stuff and configuration.The USB to serial cable could need a windows driver.Linus often has the drivers.but in ether case the driver is NOT on the server.C

author: TopLoser
author_rank: Unknown
timestamp: May 30, 2018, 09:09:03 am
content: Thanks C, I quite like that idea.Customer might kick up a fuss with having another PC appear on their network, but I can ask... They’re generally ok with ‘dumb’ devices being connected to it but anything resembling a PC and people start shouting ‘security’ and ‘maintenance’.Certainly got possibilities though.

author: bob225
author_rank: Frequent Contributor
timestamp: May 30, 2018, 09:54:36 am
content: This is what I said in my previous posts just put the usr convertor in server mode - clone the ip and mac of the printerorjust purchase a network rfid reader/writer

author: TopLoser
author_rank: Unknown
timestamp: May 30, 2018, 10:24:23 am
content: Tried that Bob225, got one of them on my desk. Can’t get it to work. I’ll give it another go if you’re convinced it’s possible...There’s a robot and automatic applicator involved, it’s not ‘quite’ as simple as just a RFID tag - I need access to the other label data to determine pallet sizes and other stuff.

author: C
author_rank: Super Contributor
timestamp: May 30, 2018, 07:58:30 pm
content: TopLoserAs I stated that server can easily send that printer data to another computer.If they have a windows computer close to RFID that could be cheap option. The problem with this is it takes a more time to configure windows.On the other hand linux is much cheaper when adding a computer. And ones like the Raspberry Pi makes it even easer as the OS is on an SD card.You can easily make a backup copy.Linus is also built more for remote management.SSH lets you get a remote command line, need putty on windows for this. By using SSH and putting a copy of Raspbian OS on SD card you can do it all.You want WEB management load webmin and get something like you see on a lot of devices these days.Need to remember that the cloud is mostly built on linux or unix like OS and with simple tools it is easy to manage a huge number of computers.I often use a program called "Ansible" to build,configure & update a bunch of linux computers.If now or in the future you need to make changes, you can do it.Need more then what is in printer stream again this is a good choice.You could even have a web page showing status of palletsIf customer likes it, linux makes more locations easer.C