Python socket communication with HP print server [closed]

2024/10/10 12:24:20

I have a HP Laserjet 2550n with integrated print server connected to the local network on 192.168.1.100. Unfortunately, the client "toolbox" software that told you the toner status etc only runs under Windows XP. I have used Wireshark to listen to the communication, using an old XP machine, and would like to write my own little program (prob under python) to receive the xml with all the info about the printer. I have managed to use Putty with a "RAW" connection to 192.168.1.100:9220 to repeat the communication below and receive the XML (I have not attached the whole XML, only the beginning).

I am struggling though where to start this with python. I have used a simple socket client to establish a pipe, and socket.recv sends me the first line (220 JetDirect GGW...). When I socket.send(bytes("TIME 600","UTF-8")) and then try and receive again, the interactive shell "freezes".

I would really appreciate any pointers on how to get python to have the conversation as below with the print server. Many thanks!

220 JetDirect GGW server (version 2.0) ready
SERV HP-DC-WEB
250 96 HP-DC-WEB
TIME 600
200 OK
DEVI
255 MFG:Hewlett-Packard;CMD:PJL,PML,BIDI-ECP,MLC,PCL,POSTSCRIPT,PCLXL;MDL:hp color LaserJet 2550 series;CLS:PRINTER;DES:Hewlett-Packard color LaserJet 2550 series;MEM:MEM=57MB;1284.4DL:4d,4e,1;COMMENT:RES=600x2;
OPEN 96
200 OK
DATA
200 OK
GET /hp/device/info_device_status.xml HTTP/1.1
HOST:localhost:5225
USER-AGENT:hp Proxy/2.5
CONTENT-LENGTH:0HTTP/1.1 200 OK
Server: Virata-EmWeb/R6_0_1
Transfer-Encoding: chunked
Content-Type: text/xml
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Cache-Control: no-cache
Pragma: no-cache0000013f
<?xml version="1.0" encoding="UTF-8" ?>...</xml>
Answer

It's very hard to debug your code without seeing more than two tiny snippets, but I have a guess:

socket.send(bytes("TIME 600","UTF-8"))

There's no newline there. And this appears to be a line-based protocol. So presumably the server is waiting for the rest of the line, which never comes, and therefore it's never sending anything back in response, and therefore your next recv just blocks forever.

It's worth mentioning that the protocol may need \r\n rather than just \n, especially if the device is as Windows-centric as it seems.


Meanwhile, sockets are byte streams, not message streams; send is not guaranteed to send your entire message; recv is not guaranteed to receive an entire message from the other side.

For your simple app, you can fix this pretty easily: Use sendall instead of send, and either loop over recv until you have a complete line, or, even simpler, just use makefile.

https://en.xdnf.cn/q/118460.html

Related Q&A

Why are torch.version.cuda and deviceQuery reporting different versions?

I have a doubt about the CUDA version installed on my system and being effectively used by my software. I have done some research online but could not find a solution to my doubt. The issue which helpe…

How to have 2 advertisements in BLE(BlueTooth Low Energy)?

Im working on BLE advertisement. Id like to know if its possible to have 2 advertisements in BLE. I need to have both service data and manufacturer data. Im using Python. The code is based on https://g…

How to get Python script to write to existing sheet

I am writing a Python script and stuck on one of the early steps. I am opening an existing sheet and want to add two columns so I have used this:#import the writer import xlwt #import the reader impor…

Python3 - getting the sum of a particular row from all the files [closed]

Closed. This question needs debugging details. It is not currently accepting answers.Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to repro…

Selenium Headers in Python

how can I change my headers in Selenium like I do in requests ,I want to change my cookies and headers . from myCookie import cookie from selenium import webdriver from selenium.webdriver.common.by imp…

Get unique groups from a set of group

I am trying to find unique groups in a column(here for letter column) from an excel file. The data looks like this:id letter1 A, B, D, E, F3 B, C2 B75 T54 K, M9 D, B23 B, D, A34 X, Y, Z67 X, Y12 E, D15…

Move and Rename files using Python

I have .xls files in a directory that i need to move to another directory and renamed. Those files are updated monthly and will have a different name each month. For instance the current name is Geoc…

AttributeError: StringVar object has no attribute encode

Im making a program to generate an encrypted qr from the message and password provided, but it keeps on returning the same error.I tried passing the value to other variablesmain.pyfrom tkinter import *…

Reading specific column from a csv file in python

I am writing some python code to practice for an exam in January. I need to read the second column into my code and print it out. If possible i also need to add data to specific columns. The code i hav…

Date Time Series wise grouping of data and distribution

I am trying the merge the datetime series with a repository data while grouping by name and summing the values. File1.csv Timeseries,Name,count 07/03/2015 06:00:00,Paris,100 07/03/2015 06:00:00,Paris,6…