V2.0 Download - Ethernet Printer Test Program
# Print test success, msg = raw_print(ip, TEST_PAGE) result["raw_print"] = success if not success: result["errors"].append(f"Print failed: msg")
# Option 1: Single IP ip = input("Enter printer IP (or range e.g., 192.168.1.10-20): ").strip()
#!/usr/bin/env python3 """ Ethernet Printer Test Program v2.0 Supports: RAW TCP on port 9100, LPD on port 515, optional SNMP. """ import socket import time import json import sys import threading from concurrent.futures import ThreadPoolExecutor from datetime import datetime try: from pysnmp.hlapi import * SNMP_AVAILABLE = True except ImportError: SNMP_AVAILABLE = False ========== CONFIGURATION ========== TEST_PAGE = b"\x1b%-12345X@PJL JOB\r\n@PJL ENTER LANGUAGE=PCL\r\n\x1bEPrinter Test Page v2.0 - Ethernet Test\x1b&l0o0\x1bE\x1b%-12345X@PJL EOJ\r\n" RAW_PORT = 9100 LPD_PORT = 515 TIMEOUT = 5 THREADS = 5 ========== CORE FUNCTIONS ========== def test_port(ip, port): """Test if a TCP port is open.""" try: with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: s.settimeout(TIMEOUT) s.connect((ip, port)) return True except: return False
# SNMP toner toner = get_snmp_toner(ip) if toner is not None: result["toner_level"] = toner ethernet printer test program v2.0 download
def get_snmp_toner(ip, community='public'): """Get toner level (OID for black toner).""" if not SNMP_AVAILABLE: return None oid = ObjectIdentity('1.3.6.1.2.1.43.11.1.1.9.1.1') errorIndication, errorStatus, errorIndex, varBinds = next( getCmd(SnmpEngine(), CommunityData(community), UdpTransportTarget((ip, 161)), ContextData(), ObjectType(oid)) ) if errorIndication or errorStatus: return None return int(varBinds[0][1])
Save the following code and run it.
def test_single_printer(ip, name="Unknown"): """Run all tests on one printer.""" result = "ip": ip, "name": name, "timestamp": datetime.now().isoformat(), "port_9100": test_port(ip, RAW_PORT), "port_515": test_port(ip, LPD_PORT), "raw_print": None, "throughput_kbps": None, "toner_level": None, "errors": [] # Print test success, msg = raw_print(ip, TEST_PAGE)
if not printers: print("No printers found.") return
print(f"\n[*] Testing len(printers) printer(s) with THREADS threads...\n") results = []
def throughput_test(ip, size_kb=1024): """Send 1 MB of dummy data, measure speed.""" data = b'U' * (size_kb * 1024) try: with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: s.settimeout(TIMEOUT) s.connect((ip, RAW_PORT)) start = time.time() s.sendall(data) elapsed = time.time() - start speed_kbps = (size_kb * 8) / elapsed # kilobits per second return round(speed_kbps, 2) except: return None if '-' in ip: start_ip, end_ip = ip
pip install pyinstaller pyinstaller --onefile ethernet_printer_tester_v2.py The .exe will be in the dist folder.
if '-' in ip: start_ip, end_ip = ip.split('-') printers = discover_printers(start_ip, end_ip) else: printers = [ip]
with ThreadPoolExecutor(max_workers=THREADS) as executor: futures = [executor.submit(test_single_printer, p) for p in printers] for future in futures: res = future.result() results.append(res) print(f"✅ res['ip'] | RAW: res['port_9100'] | Print: res['raw_print'] | Speed: res['throughput_kbps'] kbps")
