Send Zebra Certificate through socket using ZPL command

// Expert user has replied.
P Pedro Zapata 1 year 1 month ago
122 3 0

Hi everyone, 

I'm trying to send a certificate file .NRD using a Python Socket and ZPL commands. At this moment the printer (ZT411) receives the file but it's not working. This certificate is used for weblink, i'm trying to send it to multiple devices to the same time. I think that my ZPL command is wrong or i skipped a step. Can anyone help me to understand if i need someting else?

This is my code:

import socket
import os
from _thread import *
from flask import Flask, request
import re
import zebra


def zebra (cert_test, hosts):
    port = 9100
    for host in hosts:
        try:
            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            s.settimeout(1)
            result = s.connect_ex((host, port))
            print(result)
            if result == 0:
                s.send(str.encode(cert_test))
                print (s.recv(1024)) #ACK
                return ("  [*] Port " + str(port) + " open!" + host)
                
            else: return("[+] CLOSE HOST " + host + ":" + str(port))
        except:
            pass

hosts = ['10.XX.XX.XX']

#I'm sending the certificate in binary format Example: "2D2D2D2D2D424" 
cert_test = cert_test = "^XA~DYE:WEBLINK1_CA,A,NRD,2182,,A,<My Cert in Binary>^XZ"


zebra (cert_test,hosts)

 

Please register or login to post a reply

3 Replies

P Pedro Zapata

 

Hi everyone, 

Now i'm using another method, sending the whole file over a tcp socket with a .zpl file. But the result it's the same, the printer don't read the certificate. Can anyone help me?

 

import socket
import tqdm
import os


separator = "<SEPARATOR>"
buffer_size = 4096


host = "10.27.XX.XX"


port = 9100

filename = "prueba.zpl"

filesize = os.path.getsize(filename)

s = socket.socket()

print (f"[+] Conectando a la impresora {host}:{port}")
s.connect((host, port))
print ("[+] Conectado.")

s.send(f"{filename}{separator}{filesize}".encode())
#s.send(str.encode(filename))

progress = tqdm.tqdm(range(filesize), f"Sending {filename}", unit="B", unit_scale=True, unit_divisor=1024)

with open(filename, "rb") as f:
    while True:
        # read the bytes from the file
        bytes_read = f.read(buffer_size)
        if not bytes_read:
            # file transmitting is done
            break
        # we use sendall to assure transimission in 
        # busy networks
        s.sendall(bytes_read)
        # update the progress bar
        progress.update(len(bytes_read))
# close the socket
s.close()
! CISDFCRC16
BA0B
privkey.nrd
0000037B
E3AF
-----BEGIN RSA PRIVATE KEY-----
MIICXgIBAAKBgQDQXu/E9YuGlScfWQepZa8Qe/1mJRpmk8oPhPVvam/4M5/WaWQp
3/p1f8J17/hDH8fFq5Dnx3/tHaU7A4SKO8GeghX5hnp/mt4tuQEvsXkCrcgS1puz
z5dbO7ThhuzxYClnr7uiXPvSRXawgwDTPas+0q/6gHeUSXtA0EofuIyv7wIDAQAB
AoGBAJPnf3wn6wT5pE59DJIyakRiLmkt1wKOzvObJfgS7i2Yv1EbeAy9PnPe3vKG
Bovm6A+oi2/qTSTLUTiFc7QHXJPVxLmRiHMbf1Q8j+VJkGTpWt8EY/Px+HSM2HAP
jqd+Im0IiE9RQPsxWQH9UaauF6nl5gIfMF74BIPsVzFXLFfxAkEA6zSrCKCycE/P
14cjZibnLiWxdL3U3I9eWuhmIS37RB6UJF

prueba.zpl file

S Steven Si

The printer needs a reset in order to read the cert file. Can you try to FTP the cert to the printer's E: drive to see if the printer reads the cert file? If the printer still doesn't read the cert file after the FTP, it might be the cert file is not valid.

P Pedro Zapata

Thanks Steven i will try with other Cert. 

CONTACT
Can’t find what you’re looking for?