adamZ88 has asked for the wisdom of the Perl Monks concerning the following question:

Monks, this is my very first post. I am new to Perl, and SNMP. I however have more knowledge on Cisco IOS. When I create any perl script utilizing SNMP_util and it pulls a value that is HEX-string, the output looks like so: "180.20.137.96.107.0:▒▒`k'" The funny looking characters are supposed to be a mac address Expressed like so: FF FF FF FF FF FF. The walk works just fine if I run it from shell with net-snmp the Hex-String displays just fine. The issue happens with any OID that is supposed to pull Hex-Strings. Please Help. I think that the result of the snmpwalk is not displaying properly. But the best way to explain it is "it looks like a mushed together bar-code, it is by no means any alphanumeric characters. Additionaly, I have not found any documetation on SNMP_util.pm. Can you please point me to where I can find that Documentation? Thanks!

#!/usr/bin/perl use SNMP_util; $comunity = "rushnet"; $host = shift; $testOid = shift; print "----------------------------------------WALK------------------- +-------------\n"; (@result) = &snmpwalk("$comunity\@500\@$host", "$testOid"); foreach $lineBuf (@result){ print "$lineBuf\n";} print "----------------------------------------GET-------------------- +------------\n"; $result = &snmpget("$comunity\@$host", "$testOid"); #chomp($result); print "$result\n";

Replies are listed 'Best First'.
Re: Hex-String retrieval is unsuccesful on SNMP Walk form Perl
by Marshall (Canon) on Apr 12, 2016 at 18:48 UTC

      Ok, I provided my code. I will look at your recommendations. Thanks for prompt reply

Re: Hex-String retrieval is unsuccesful on SNMP Walk form Perl
by VinsWorldcom (Prior) on Apr 12, 2016 at 19:17 UTC

    I too use Net::SNMP as offered above. You may have to try to unpack the hex string as a MAC address is simply a hex string. If it's stored that way, you'll get the "funny looking characters" if you try to print it without converting to ASCII first.

    printf "%s\n", unpack ("H*", $HexStringMAC);

    Where $HexStringMAC above (obviously) contains the value of your returned Hex string that should be interpreted as a MAC address.

      Vins, Thank you. I had previously tried unpacking, and I was getting the same result. I will try Net::SNMP eventually, but since I have quite a few scripts with SNMP_util, I wanted to stick with that, but like I said I cannot find any Documentation for it.

        I updated my post with a link to SNMP-util, see if that helps.