Skip to content

Instantly share code, notes, and snippets.

@Bloody-Badboy
Created July 25, 2023 13:09
Show Gist options
  • Save Bloody-Badboy/c16b6ee97439b858ab78733428c79a57 to your computer and use it in GitHub Desktop.
Save Bloody-Badboy/c16b6ee97439b858ab78733428c79a57 to your computer and use it in GitHub Desktop.
EPSON L3250 Series Waste Ink Counter Reset Using SNMP Protocol (Remove Service Required)
import re
from easysnmp import Session
from pprint import pprint
from struct import pack, unpack
printer_ip = "10.0.0.222"
session = Session(hostname=printer_ip, community="public", version=1, timeout=1)
password = [74, 54]
debug = False
def read_eeprom_addr(addr: int) -> str:
split_addr = unpack("BB", pack(">H", addr))
oids = f"1.3.6.1.4.1.1248.1.2.2.44.1.1.2.1.124.124.7.0.{password[0]}.{password[1]}.65.190.160.{split_addr[1]}.{split_addr[0]}"
response = session.get(oids).value
response = re.findall(r"EE:[0-9A-F]{6}", response)[0][3:]
chk_addr = (int(response[:2], 16), int(response[2:4], 16))
value = response[4:6]
if split_addr != chk_addr:
raise ValueError(
f"Address and response address are not equal: {split_addr} != {chk_addr}"
)
if debug:
print(f"Address: {split_addr} {hex(addr)} Value: 0x{value}")
return value
def write_eeprom(addr: int, value: int):
split_addr = unpack("BB", pack(">H", addr))
value_before = read_eeprom_addr(addr)
oids = f"1.3.6.1.4.1.1248.1.2.2.44.1.1.2.1.124.124.16.0.{password[0]}.{password[1]}.66.189.33.{split_addr[1]}.{split_addr[0]}.{value}.78.98.115.106.99.98.122.98"
session.get(oids).value
value_after = read_eeprom_addr(addr)
if debug:
print(
f"Address: {split_addr} {hex(addr)}, Value Before: 0x{value_before}. Value After: 0x{value_after}"
)
if value != int(value_after, 16):
raise ValueError(
f"Failed to write value to Address {split_addr} {hex(addr)}, Value:{value}"
)
def read_eeprom_multi(addrs: list[int]) -> list[str]:
return [read_eeprom_addr(oid) for oid in addrs]
def transform_addrs(base_addr: int, end_addrs: list[int]):
return list(map(lambda n: ((base_addr << 8) | (n & 0xFF)), end_addrs))
def read_error_logs():
for i in range(0, 5):
address = [32 + (2 * i), 32 + (2 * i) + 1]
address = transform_addrs(0x1, address[::-1])
code = int("".join(read_eeprom_multi(address)), 16)
print(f"Last printer falal error code {i+1} : {code} ({hex(code)})")
for i in range(0, 5):
address = [39 + (1 * i)]
address = transform_addrs(0x7, address[::-1])
code = int("".join(read_eeprom_multi(address)), 16)
print(f"Last printer scanner error code {i+1} : {code} ({hex(code)})")
for i in range(0, 5):
address = [244 + (2 * i), 244 + (2 * i) + 1]
address = transform_addrs(0x7, address[::-1])
code = int("".join(read_eeprom_multi(address)), 16)
print(f"Last general scanner error code {i+1} : {code} ({hex(code)})")
def reset_error_logs():
for i in range(0, 5):
address = [32 + (2 * i), 32 + (2 * i) + 1]
address = transform_addrs(0x1, address[::-1])
write_eeprom(address[0], 0x0)
write_eeprom(address[1], 0x0)
for i in range(0, 5):
address = [39 + (1 * i)]
address = transform_addrs(0x7, address[::-1])
write_eeprom(address[0], 0x0)
for i in range(0, 5):
address = [244 + (2 * i), 244 + (2 * i) + 1]
address = transform_addrs(0x7, address[::-1])
write_eeprom(address[0], 0x0)
write_eeprom(address[1], 0x0)
def read_waste_counter():
waste_counter1 = int(
"".join(read_eeprom_multi(addrs=transform_addrs(0x0, [48, 49][::-1]))), 16
)
waste_counter2 = int(
"".join(read_eeprom_multi(addrs=transform_addrs(0x0, [50, 51][::-1]))), 16
)
waste_counter3 = int(
"".join(read_eeprom_multi(addrs=transform_addrs(0x0, [252, 253][::-1]))), 16
)
print(f"Waste Counter 1 : {(waste_counter1 / 6345) * 100}%")
print(f"Waste Counter 2 : {(waste_counter2 / 3416) * 100}%")
print(f"Waste Counter 3 : {(waste_counter3 / 1300) * 100}%")
model = session.get("1.3.6.1.2.1.1.5.0").value
serial = "".join(
chr(int(value, 16))
for value in read_eeprom_multi(
addrs=transform_addrs(0x6, [68, 69, 70, 71, 72, 73, 74, 75, 76, 77])
)
)
print(f"Device Model: {model}")
print(f"Serial No: {serial}")
read_error_logs()
# reset_error_logs()
read_waste_counter()
print("Resetting...")
# waste counters [two bytes]
for value in transform_addrs(0x0, [48, 49, 50, 51, 252, 253]):
write_eeprom(value, 0)
read_waste_counter()
@minhng99
Copy link

minhng99 commented Mar 9, 2024

I'm getting an error

Traceback (most recent call last):
  File "/home/user/L3250_Reset.py", line 125, in <module>
    read_error_logs()
  File "/home/user/L3250_Reset.py", line 62, in read_error_logs
    code = int("".join(read_eeprom_multi(address)), 16)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/L3250_Reset.py", line 51, in read_eeprom_multi
    return [read_eeprom_addr(oid) for oid in addrs]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/L3250_Reset.py", line 51, in <listcomp>
    return [read_eeprom_addr(oid) for oid in addrs]
            ^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/L3250_Reset.py", line 20, in read_eeprom_addr
    response = re.findall(r"EE:[0-9A-F]{6}", response)[0][3:]
               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^
IndexError: list index out of range

response = session.get(oids).value

the response is outputting ||:41:NA;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment