Snmp Value as Hex String


I’m trying to obtain the MAC Address of printers and using snmpwalk, I can see it returns a hex-string like this:

. = HEX-STRING: 1C7D220D0768

Base on the above OID, i cobbled up the below code to return the Mac Address:

$PrinterAddress = ""
$SNMP = New-Object -ComObject olePrn.OleSNMP
$SNMP.Open($PrinterAddress, "public", 2, 1000)
$MacAddress = $SNMP.Get(".")

But the above returns the following value:


I’m not even sure where to go from here. Any pointers would be much appreciated.


Does that happen to be a fujifilm printer? Because that hex string looks like a MAC address and when I look up the MAC it shows as a fujifilm

Yes, Fuji Xerox to be exact.

I’m trying to return that mac address hex string thingee “1C7D220D0768” but getting some weird 3 character thingee instead.

I tried several printers with your example code (which is the first google record) and a few modules that used custom DLLs. I wasn’t having much luck because they would return gibberish from different printers. However SNMPWalk works great. I played around with this and ended up making this function.

Function Get-PrinterMacAddress {
        $Community = 'Public',
        $Port = 161,
        $Timeout = 5

    begin {
        $oidlist = '','.'
        $snmpwalk = Join-Path $env:TEMP 'SNMPWalk\snmpwalk.exe'

        if(-not (Test-Path $snmpwalk)){
            $zipfile = Join-Path $env:TEMP
            $destination = New-Item (Split-Path $snmpwalk -Parent) -Force -ItemType Directory
            Invoke-WebRequest -UseBasicParsing '*19n1cvv*_ga*MjAzNzczMjA0NS4xNjY3OTc4ODUx*_ga_BEFD2E3R5Z*MTY2Nzk3ODg1MC4xLjEuMTY2Nzk3ODg4My4yNy4wLjA.' -OutFile $zipfile
            $shell = New-Object -ComObject Shell.Application

    process {
        foreach($printer in $IP){
            foreach($oid in $oidlist){
                $output = & $snmpwalk -r:$printer -os:"$oid.0" -op:"$oid.2" -p:$Port -t:$Timeout -csv

                Write-Verbose "[$printer] $output"

                $results = $output |
                    ConvertFrom-Csv -Header OID, Type, Value, Value1 |
                        Where-Object Value -match '^(\w\w\s){6}\s+?$'
                if(-not $results){

                $mac = $results.Value.Trim() -replace '\s',':'

                        IP  = $printer
                        MAC = $mac

You can test it out with this example

$PrinterAddress = "", "", ""

Get-PrinterMacAddress -IP $PrinterAddress

You can also pipe the IPs to the function

$PrinterAddress = "", "", ""

$PrinterAddress | Get-PrinterMacAddress -Verbose -Timeout 1

The function works a treat. Much appreciated.

I was playing around with snmpwalk.exe and the -os and -op parameters took a bit of trial and error to figure out. Since I only needed the value from “.”, I tried -os and -op with the same oid but nothing was returned.

Turns out you need to actually give a range of oids and it’ll return all except the starting oid (-os). So in my case, I needed to …

$PrinterAddress = ""
$OidStart = "."
$OidEnd = "."
$SnmpWalk = "\\Path\to\SnmpWalk.exe"
$MacAddress = (& $SnmpWalk -r:$PrinterAddress -os:$OidStart -op:$OidEnd | Select-String -Pattern "Value" | Out-String).Trim().Split("=")[3].TrimStart() -replace " ",":"

… and it’ll return the value of “.”, but not “.”.

If $OidStart is .1 and $OidEnd is .2, it’ll return the value of .2 only … which in my case was null as only interface 1 (". had a MAC address value.