Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perl SNMP strange data received 1

Status
Not open for further replies.

Gassner

ISP
Jan 30, 2002
19
0
0
BR
Hi, im using snmp_util to retrieve arp table of a host. All data is shown ok, but when mac addresses are printed, some strange characters appear.

Any idea?

Thanks,

Rafael Gustavo Gassner


#! /usr/bin/perl -w
use SNMP_util;
#use SNMP_Session;
#use BER;

$ip="10.10.10.10";
$comm="public";
$poort="161";
$timeout="100";
$retries="2";
print "Coletando indices do equipamento $ip\n";
@indice=&snmpwalk("$comm\@$ip:$poort:$timeout:$retries","1.3.6.1.2.1.4.22.1.1");
print "Coletando enderecos MAC do equipamento $ip\n";
@fisico=&snmpwalk("$comm\@$ip:$poort:$timeout:$retries","1.3.6.1.2.1.4.22.1.2");
print "Coletando enderecos IP do equipamento $ip\n";
@rede=&snmpwalk("$comm\@$ip:$poort:$timeout:$retries","1.3.6.1.2.1.4.22.1.3");
print "Coletando tipos de endereco do equipamento $ip\n";
@tipo=&snmpwalk("$comm\@$ip:$poort:$timeout:$retries","1.3.6.1.2.1.4.22.1.4");

$i=int(@indice);
print "$i\n";
while($i ne 0)
{
$i--;
($oid, $indice[$i]) = split(/\:/, $indice[$i]);
($oid, $fisico[$i]) = split(/\:/, $fisico[$i]);
($oid, $rede[$i]) = split(/\:/, $rede[$i]);
($oid, $tipo[$i]) = split(/\:/, $tipo[$i]);

print " $indice[$i] $fisico[$i] $rede[$i] $tipo[$i]\n";
}
 
they look like

1 @§HS 10.96.156.160 3
1 @§Q 10.96.156.76 3
1 °Ãz/à 10.96.156.73 3
1 °Ãz1 10.96.156.71 3
1 °Ãz0, 10.96.156.68 3
1 @§I 10.96.156.61 3
1 @§T¯ 10.96.156.57 3
1 [(¼à 10.96.156.55 3
1 ÃF 10.96.156.1 3
 
Try adding this line just before the print statement.
Code:
$fisico[$i] = unpack 'H*', $fisico[$i];
The mac addresses are returned as hex values and you need to tell Perl to print the actual hex, not the characters that have those hex values.

jaa
 
justice41 rulez!

Worked perfectly.

Thanks a lot
 
tsk tsk.....

*Much* too clever Jaa, we don't like that sort of thing around here you know :) Mike

Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top