Capture data sent to printer - python

I have a POS application running on windows machine which prints data and does not allows to save the data. I try to print to pdf but does not seem possible. I would like to capture the data send to the printer maybe from the USB port and then later convert it to human readable text. I am pretty new to this, so a detailed answer with all steps will be much appreciated. Also to note its a thermal printer, just so if it makes difference!

Related

Can scapy decrypt WPA2(802.11) on the fly?

Long time ago i used netfilter_queue to create small program to monitor packets and block unwanted connections. So this program delays new connection by some time (miliseconds) and passing packets to userspace, but delay is perceptible when using firefox.
Next i figured out i can sniff packets and allow on the beginning all new connections to later block unwanted connections without delay. So everything would be fine, but when i switched to wifi network, realized i need to decrypt wifi(wpa2) frame first, and i wonder if it is possible to do it in scapy?
I'm looking something similar to dot11decrypt but in python.
Cant provide library i used before, it was not scapy, because its on another computer i don't have access right now. And i don't remember the name it was like 10 yrs ago. And sniffer was written in python module socket.
EDIT:
Now when i know scapy by itself can't decrypt WPA2 i found that there are tools written in python to crack wpa2 password, so it should be possible to write program to sniff and decrypt WPA2 in python to get IP:PORT from packets.
But whole operation is not that strait forward. Need to know more about WPA2 protocol. Right now i don't have much time to do it but in spare time i will try to write something.
So i dig, and dig, and I'm happy that i didn't stop.
The answer is no, scapy can't decrypt WPA2(802.11).
I had also used decrypt and decode word like they were the same words, my bad. So when i was talking about decode 802.11 i was talking about decrypting WPA2(802.11).
I just deduced reading EagleEye paper, their software uses dot11decrypt and libtins to do that and scapy to analyses data. I didn't have time to read whole paper, but think i understand their logic. Page 3 figure 1 have a nice picture.
I start digging again and their software is on github, pretty nice software.
So that would be all. If I'm wrong correct me.

Python barcode scanner serial trigger

I'm messing around with a Honeywell 4600 barcode scanner in python, configured as a serial device. All is well and I can read barcodes with it, but I would like to test the serial trigger option instead of pressing the trigger all the time.
The manual is very brief on this feature and only states "SYN T CR" has to be written to the device to activate the serial trigger
ser.write('SYN T CR')
does not seem to do much.
Can someone point me in the right direction? Thank you!
This happens because you coded the abstract expression written in the document as raw output data.
The document represents 3 bytes of data transmission.
'SYN' and 'CR' are the following hexadecimal numbers.
'SYN' = \x16
'CR' = \x0d or escape sequence \r
'T' is an ordinary ASCII character.
Whitespace is used to separate the data in the document, not data to send.
You should write like this. Please try it.
ser.write(b'\x16T\r')
Alternatively, perhaps even you may need to prefix it.
Send data to Honeywell Xenon 1902 barcode reader via virtual com port
In that case, please try the following transmission.
ser.write(b'\x16M\r\x16T\r')

How to send raw string to a dotmatrix printer using python in ubuntu?

I have a dot-matrix printer LX-300 connected to my computer through the network. How do I send a raw string with ESCP characters directly to my printer in Python?
The computer is connected to the printer through another computer. I need to send a raw string because LX-300 image printing result is blurry.
The Problem
To send data down this route:
Client computer ---> Server (Windows machine) ---> printer (dot-matrix)
...and to not let Windows mess with the data; instead to send the raw data, including printer control codes, straight from the client computer.
My Solution
Here's how I solved a near-identical problem for a small in-house database application:
Step 1) Make the printer network-accessible without Windows getting its fingers in the data routed to it. I accomplished this by installing the printer using the "Generic/Text Only" driver, then installing
RawPrintServer on the Windows machine connected to the printer.
Step 2) Send raw data over the network to the TCP/IP port specified when you set up RawPrintServer (default is 9100). There are various ways to do that, here's what I did:
data = b"\x1B#A String To Print\x1B#" # be sure to use the right codes for your printer
ip_addr = 123.123.123.123 # address of the machine with the printer
port = 9100 # or whatever you set it to
s = socket.socket()
try:
s.connect((ip_addr, port))
s.send(data)
except:
# deal with the error
finally:
s.close()
Background
I thought about the problem in two parts:
Client machine: spitting out the data I need from Python with the correct formatting/control codes for my printer, and sending it across the network
Print server machine: transmitting the data to the locally connected printer
Number 1 is the easy part. There are actually some libraries in PyPI that may help with all the printer codes, but I found most of them are aimed at the little point-of-sale label printers, and were of limited use to me. So I just hard-coded what I needed into my Python program.
Of course, the way you choose to solve number 2 will effect how you send the data from Python. I chose the TCP/IP route to avoid dealing with Samba and Windows print issues.
As you probably discovered, Windows normally tries very hard to convert whatever you want to print to a bitmap and run the printer in graphics mode. We can use the generic driver and dump the data straight into the (local) printer port in order to prevent this.
The missing link, then, is getting from the network to the local printer port on the machine connected to the printer. Again, there are various ways to solve this. You could attempt to access the Windows printer share in some way. If you go the TCP/IP route like I did, you could write your own print server in Python. In my case, the RawPrintServer program "just worked" so I didn't investigate any further. Apparently all it does is grab incoming data from TCP port 9100 and shove it into the local printer port. Obviously you'll have to be sure the firewall isn't blocking the incoming connections on the print server machine. This method does not require the printer to be "shared" as far as Windows is concerned.
Depending on your situation (if you use DHCP), you might need to do some extra work to get the server's IP address in Python. In my case, I got the IP for free because of the peculiarity of my application.
This solution seems to be working out very well for me. I've got an old Panasonic printer running in Epson ESC/P compatibility mode connected to a Windows 7 machine, which I can print to from any other computer on the local network. Incidentally, this general idea should work regardless of what OS the client computer is running.
Ultimately, you will need and want to write your own wrapper/script to do this. And since you are using a distribution of Linux, this is relatively easy.
On a Linux OS, the simplest way to issue a print job is to open a subprocess to the lpr. Generally, using lpr lets you access the printer without the need to be logged in as root (being a superuser), which is desirable considering the amount of damage that can be done while logged in as a "superuser".
Code like the following:
import subprocess
lpr = subprocess.Popen("/usr/bin/lpr", stdin=subprocess.PIPE)
lpr.stdin.write(data_to_send_to_printer)
Should be a good jumping off point for you. Essentially, this code should allow you to accomplish what you need.
Be careful though; depending on your privilege levels, a call to open a subprocess might need root level/Superuser permissions.
Subprocesses generally inherit the User IDs and access rights by the user that is running the command. For example, if the subprocess is created by a root user, then you will need root user/Superuser rights to access that subprocess.
For more information, check out the hyperlinks I've included in the post.
Good luck!

Retrieve data from hardware(eg CCTV,RFID) if library/API is not available

I want to access data from devices like RFID reader,CCTV camera which will be connected to a device which has SUSE Linux in it.This is a proprietary device --> Huawei AR515.
But, I am not sure in what format, data will be produced by these devices. If i want to get data, say using Python/C++ what will I have to do?
Help in this regard will be appreciated
In python, maybe this way can helps you
Reading serial data in realtime in Python
In C/C++ for linux platform, you can read directly in /dev/.
In both cases, is mandatory knows whats commands and sequences the device require. In general lines, if you before never try this and you're begginer, the first steps more appropriate are the AT commands.
This can help How to Send/Receive SMS using AT commands?

Control hardware (a Raman spectrometer) using Python

I have an old Raman spectrometer (one of these - http://www.camo.com/downloads/partners/deltanu/Inspector_Raman_Datasheet.pdf) and I'd like to write code, ideally in Python, that can provide it with input parameters, operate it and receive data from it.
The spectrometer connects to a PC via a USB, although it is assigned to a virtual COM port. I currently control it using an .exe file provided by the company that used to sell it, that I believe was produced using LabVIEW.
Is it possible to write my own code to control this sort of hardware? How can I pass parameters and commands to hardware? What information would I need to know to do this?
Although I'm a fairly proficient Python coder, this is a brand new area for me, so any advice on where to start would be super appreciated. I'm open to coding in another language if that would be more appropriate. And let me know if I need to provide any more info.
Cheers, Liam
A google search for the device model name and "programming manual" is usually where I start with something like this. Those keywords hopefully turn up something from the manufacturer that tells you how to do exactly what you're trying to do, and a lot of them include code samples. Unfortunately, with the little information I have on your device, I couldn't find anything. That's going to make it much, much harder.
Everything beyond this point is a guess based on what I've seen before. Typically, if a LabVIEW program interacts with a device over a virtual COM port, the program sends an ASCII command to the device using the protocol defined in the manual, and then receives ASCII data in return. You can try sniffing that data with the NI I/O Trace tool (http://www.ni.com/download/ni-io-trace-14.0.1/4914/en/) while running the manufacturer's application, and then trying to make sense of the flood of data that you see on that port.
It could also be a Modbus device, which may help you figure out the structure of the communication.
In short, this'll be tough without a programming manual, but there is some hope. Good luck!

Categories