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 issues

Status
Not open for further replies.

sonlexuz

Programmer
Oct 12, 2002
1
0
0
US
Hi.

Does anyone has a perl script to extract the ARP table using snmp?
 
You want the MIB-II table ip.ipNetToMediaTable

I have used perl SNMP module in the past, but you may find things easier if you use the NET-SNMP utilities (formerly UCD-SNMP). These are available for most platforms from
If you backtick the command
`snmptable -Cf '|' -p 161 network_device public ip.ipNetToMediaTable`

You get an easily parsable result as below

SNMP table: ip.ipNetToMediaTable

ipNetToMediaIfIndex|ipNetToMediaPhysAddress|ipNetToMediaNetAddress|ipNetToMediaType
16777220|0:0:c:12:34:56|192.168.0.1|dynamic
---------------------------------------
I'm just trying to help, and am not a spokesman for my employer
 
Hi!

Ive just posted a question about some issues on walking arp tables. The code is working, but mac addresses are shown with strange values.

C ya

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";
}
 
oops... problem solved.

just add
$fisico[$i] = unpack 'H*', $fisico[$i];

before printing the variable.....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top