А АSaturday, 13 July 2024

Get address book from printer by SNMP.

Hi all.

By the way, yesterday I had to get the address book from the printer. To find out if there is a specific account there or not. Of course, you can export the book to a csv-file, but it's so tedious to go to the printer's admin web-panel every time. I wondered how it could be done remotely. And this is what ChatGPT advised me to do.

Using SNMP (Simple Network Management Protocol) is a valid approach for managing and retrieving information from network devices like printers. If your Xerox printer supports SNMP, you can indeed query it to retrieve the address book.

Here’s how you can proceed with SNMP in PowerShell:

1. Ensure SNMP is enabled on the printer: Check the printer’s settings to ensure SNMP is enabled and properly configured. You might need to consult the printer's manual for details.

2. Identify the OID (Object Identifier): You need to find the correct OID for the address book. OIDs are unique identifiers used to manage and monitor various aspects of a network device. The specific OID for the address book will depend on the printer model and its SNMP implementation.

3. Use PowerShell to query SNMP: PowerShell does not have built-in SNMP cmdlets, but you can use third-party modules like PSSNMP or SnmpSharpNet to perform SNMP queries.

Here’s an example of how to use SnmpSharpNet to perform an SNMP query:

Install and Import SnmpSharpNet

First, you need to download and reference the SnmpSharpNet library.

# Download the SnmpSharpNet.dll from the official source or a trusted repository.

# Example URL: https://github.com/lextudio/sharpsnmplib/releases

# Assume you've downloaded SnmpSharpNet.dll to C:\path\to\SnmpSharpNet.dll

Add-Type -Path "C:\path\to\SnmpSharpNet.dll"


While I don't have a specific OID for the address book for Xerox printers readily available, I can guide you through common OIDs used in Xerox printers and how to find the OID you need.


Common Xerox Printer OIDs

Xerox, like many printer manufacturers, follows standard and proprietary OIDs for different aspects of their printers. Here are some common OIDs you might encounter:

Printer MIB OIDs:

Printer Status: .1.3.6.1.2.1.43.10.2.1.4

Printer Name: .1.3.6.1.2.1.43.5.1.1.16

Vendor-Specific OIDs:

Xerox-specific OIDs usually start with .1.3.6.1.4.1.253, but you would need the specific MIB file to identify the exact OID.

Finding the Address Book OID

The best approach to finding the specific OID for the address book is to perform an SNMP walk to explore the OIDs exposed by your printer.


Performing an SNMP Walk

Here’s how to perform an SNMP walk to explore available OIDs:

Install snmpwalk:

On Windows: Install the Net-SNMP package from Net-SNMP.

On Linux: Use your package manager (e.g., sudo apt-get install snmp on Debian/Ubuntu).

Run snmpwalk:

Replace "public" with your SNMP community string and 192.168.1.100 with your printer's IP address.

snmpwalk -v 2c -c public 192.168.1.100

This command will list all available OIDs and their values. Look for entries related to the address book.


Example SNMP Walk Output

Here's a sample output from an SNMP walk on a generic printer:

SNMPv2-SMI::mib-2.43.10.2.1.4.1.1 = INTEGER: 1

SNMPv2-SMI::mib-2.43.5.1.1.16.1 = STRING: "Printer Name"

SNMPv2-SMI::mib-2.43.5.1.1.17.1 = STRING: "Xerox WorkCentre 3325"

SNMPv2-SMI::mib-2.43.7.1.1.1.1.3.1 = STRING: "Address Book Entry"

Using the Identified OID in PowerShell

Once you identify the correct OID for the address book, you can use it in your PowerShell script. Here's an example script:

# Import the SnmpSharpNet library

Add-Type -Path "C:\path\to\SnmpSharpNet.dll"

# Define the printer's IP address and SNMP community

$printerIp = "192.168.1.100"  # Replace with your printer's IP address

$community = "public"  # Replace with your SNMP community string

# Define the OID for the address book (replace with the correct OID)

$addressBookOid = "1.3.6.1.4.1.xerox.2.2.1.8.1.1.1"  # Replace with the correct OID

# Create SNMP target and community parameters

$target = New-Object SnmpSharpNet.SimpleSnmp($printerIp, $community)

# Perform the SNMP GET request

$result = $target.Get(SnmpSharpNet.SnmpVersion.Ver1, [SnmpSharpNet.Oid]$addressBookOid)

if ($result -ne $null) {

    foreach ($oid in $result.Keys) {

        Write-Host "OID: $oid, Value: $($result[$oid])"

    }

} else {

    Write-Host "Failed to retrieve SNMP data."

}

Getting Help from Xerox

If you have trouble identifying the OID, you can also reach out to Xerox support for assistance. They should be able to provide you with the necessary MIB files and specific OIDs for your printer model.

See you later.

No comments:

Post a Comment

А что вы думаете по этому поводу?

Версия на печать

Популярное