Skip to content

jsammarco/printer_levels

Repository files navigation

Printer Levels

printer_levels is a small Python toolkit for discovering network printers and reading toner or ink supply levels from them.

The project focuses on practical, real-world printer troubleshooting:

  • Scan one or more subnets for printers that respond to SNMP.
  • Read supply data from standard Printer-MIB OIDs.
  • Discover printers advertised by mDNS / Bonjour.
  • Probe printer-like hosts by common printer ports before attempting SNMP.
  • Try alternate vendor-specific and protocol-specific methods such as HP EWS XML endpoints and IPP.

This repository is useful when you want a lightweight way to inventory printers on a LAN and quickly answer questions like:

  • Which printers are reachable?
  • Which devices expose SNMP supply data?
  • Which cartridge or toner is low?
  • Is the printer discoverable by mDNS, IPP, SNMP, or HP web endpoints?

What Is In This Repository

Primary script

  • printer_levels.py Scans local subnets or user-provided CIDRs, queries printers over SNMP, and prints toner / ink levels using standard Printer-MIB OIDs.

Discovery and troubleshooting helpers

  • discover_and_query_printers.py Finds printer-like devices by checking common printer ports first, then tries to query SNMP supplies.

  • mdsn_discover.py Uses Zeroconf / Bonjour service discovery to find printers advertised on the local network.

  • ipp_levels.py Queries IPP or IPPS printer attributes such as marker-levels and related supply metadata.

  • hp_ews_levels.py Attempts to extract HP supply levels from common HP Embedded Web Server pages using simple text matching.

  • hp_ews_levels2.py Pulls structured HP consumable data from /DevMgmt/ConsumableConfigDyn.xml.

  • snmp_supply_debug.py Walks several printer supply OIDs directly to help debug missing or unexpected SNMP results.

Sample output captures

  • dump/ Contains captured HTTP and HTTPS responses from an HP printer used during troubleshooting and parser development.

How It Works

The main workflow relies on standard SNMP Printer-MIB values:

  • Printer name: 1.3.6.1.2.1.43.5.1.1.16.1
  • Supply description: 1.3.6.1.2.1.43.11.1.1.6.1
  • Supply level: 1.3.6.1.2.1.43.11.1.1.9.1
  • Supply max capacity: 1.3.6.1.2.1.43.11.1.1.8.1

When both current level and max capacity are available, the script calculates a percentage. If a printer reports special values such as -2 or -3, those are treated as unknown supply levels.

Requirements

Python 3.10+ is a safe target for this project.

Install the packages used by the scripts:

python -m pip install psutil pysnmp zeroconf pyipp requests urllib3

If you prefer, create and activate a virtual environment first:

python -m venv .venv
.venv\Scripts\Activate.ps1
python -m pip install --upgrade pip
python -m pip install psutil pysnmp zeroconf pyipp requests urllib3

Quick Start

Run the main script against a specific subnet:

python .\printer_levels.py --cidr 192.168.50.0/24

Use a custom SNMP community string if needed:

python .\printer_levels.py --cidr 192.168.50.0/24 --community mycommunity

Let the script detect local non-loopback IPv4 networks automatically:

python .\printer_levels.py

Example output:

========================================================================
OfficeJet Pro 9015  (192.168.50.222)
  - Black: 42% (42/100)
  - Tri-Color: 18% (18/100)

Script Usage

printer_levels.py

Main network scanner and SNMP supply reader.

python .\printer_levels.py --cidr 192.168.50.0/24 --community public --timeout 0.8 --retries 0 --workers 128

Key arguments:

  • --cidr CIDR to scan. Can be repeated.
  • --community SNMP community string. Defaults to public.
  • --timeout SNMP timeout in seconds.
  • --retries SNMP retry count.
  • --workers Number of concurrent worker threads.
  • --max-hosts Safety cap to prevent scanning very large address ranges by accident.

discover_and_query_printers.py

Useful when you are not sure which hosts are printers. It first looks for printer-like open ports such as 9100, 631, 515, 80, and 443, then attempts SNMP.

python .\discover_and_query_printers.py --cidr 192.168.50.0/24

mdsn_discover.py

Discovers printers advertised via Bonjour / Zeroconf.

python .\mdsn_discover.py

Note: the filename is mdsn_discover.py in this repository, even though the protocol is mDNS.

ipp_levels.py

Queries printer supplies using IPP or IPPS.

python .\ipp_levels.py --host 192.168.50.222 --path /ipp/print
python .\ipp_levels.py --host 192.168.50.222 --https --path /ipp/print

hp_ews_levels2.py

Best option here for HP printers that expose XML consumable data:

python .\hp_ews_levels2.py --ip 192.168.50.222

snmp_supply_debug.py

Walks raw OIDs and prints every returned value so you can inspect what the device is actually publishing:

python .\snmp_supply_debug.py

Before running it, edit the hard-coded IP and COMMUNITY values in the file.

Common Troubleshooting Notes

  • If no printers are found, verify the subnet and VLAN are correct.
  • If printer web pages open but SNMP fails, SNMP may be disabled or filtered.
  • If SNMP responds but no supplies are reported, the printer may not implement the standard Printer-MIB supply table.
  • If IPP returns no marker-levels, try another path such as /ipp/printer or switch between IPP and IPPS.
  • Some HP printers expose better consumable data through /DevMgmt/ConsumableConfigDyn.xml than through SNMP.
  • A combined CMY reading means the printer reports a single tri-color cartridge instead of separate cyan, magenta, and yellow levels.

Typical Use Cases

  • Small office printer inventory checks
  • Supply-level monitoring experiments
  • Printer troubleshooting on home or business LANs
  • Comparing SNMP, IPP, mDNS, and vendor web endpoints
  • Building a future scheduled reporting or alerting workflow

Limitations

  • This project currently prints results to the console and does not store them in a database.
  • Authentication beyond simple SNMP community strings is not implemented.
  • Some printers expose supply levels only through vendor-specific interfaces.
  • Large subnet scans can be noisy or slow depending on network conditions and device behavior.

Security and Network Considerations

These scripts perform active network discovery and query network services on your local environment. Run them only on networks you own or are authorized to assess.

Also note:

  • Many printers still use SNMP v1/v2c community strings such as public.
  • Some scripts intentionally disable TLS certificate verification for printer web or IPPS endpoints to work around self-signed certificates.
  • Network segmentation, guest Wi-Fi isolation, or firewall rules may prevent discovery.

Future Improvements

Possible enhancements for this project include:

  • requirements.txt or pyproject.toml
  • JSON or CSV output modes
  • Better vendor-specific parsers
  • Configurable logging
  • Scheduled reporting
  • Alerting on low-supply thresholds

ConsultingJoe.com

This project was created in a practical troubleshooting spirit. If you want help with Python automation, printer and network diagnostics, or turning scripts like this into something more operational, visit ConsultingJoe.com.

License

No license file is currently included in this repository. If you plan to share or publish the project, adding a license is recommended.

About

Python toolkit for discovering network printers and reading toner or ink supply levels from them

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages