Printers and Toner Levels ugh…

Who hates printers? Who hates replacing toner? Who hates not knowing when toner runs out only to get a frantic angry call from a C-Level wondering why they pay I.T. if they can’t replace the toner before it runs out?


Okay actually it’s pretty cool. At work we have a ton of brother printers like 15 I think. I hated having to watch my email for that ONE EMAIL that the brother printer sends by default and instead of configuring it like some barbarian I taught myself Python and coded something useful-ish. I realized that all brother printers have the same web interface and that I could scrap that web interface to get their toner levels. They don’t share the levels via SNMP, I guess I could have coded it to take a percentage of remaining pages/total pages but honestly that was boring. The link to the github where you can download they scripts I made is here:

So In there are 2 scripts.

  • 1) – displays toner levels in percentages
  • 2) – displays toner levels in color coded bars

Both scripts retrieve their “known model’ lists from Color_Printers.list and Monochrome_Printers.list. These files have to be in the same directory as the Python script you are running. The lists contain the names of the printers which values are compared against those values scrapped from the <title> tag in the web page. If a printer that you want is not listed just add it to the .list file that correlates to that printer.

The script finds the toner levels by looking in the page for the “inkLevel” table and the “tonnerremain” image. It takes the value of “tonerremain” which is the number of pixels that remain and divides that number by 56. It does this four time for color printers or once for black and white printers. Hence the need for monochrome and color lists. It writes to a log file whether it completed greping the toner level or not. ** if it didn’t the IP is not responding or the toner model is not in its respective list.**

The script then generates a HTML page of the printers toner levels, locations, IP addresses, which are hyper links to the web interface, and links to to purchase the toner for that model. It puts that webpage in the directory that is listed in the path.txt file. If the path.txt file is not found it will generate the HTML page in the same directory as that script.

It’s a continually changing and evolving script and I’ll probably add about a dozen more things to it But I’ll make sure to upload those changes to github and add anymore info here if needed. I’ll add pictures tomorrow of the script in action.

Cheers for now!

Leave a Comment