Hello Monks, I am working with SNMP and perl. I am walking oid ipNetToMediaPhysAddress oid. The results always vary, but follow the following format nn.ooo.ooo.ooo.ooo:mmm. Here is an actual example of the result of walking that oid: 258.10.73.138.11:00 00 00 00 00 00. nn=is a variable length numeric string oo is an octet(decimal from 0 - 255) mm is a hex string
I want to compare a string containing an ip address to the results of this walk for an exact match to the "oo" values, I do not care about the rest of the values. For, example I want to check if "10.73.138.11" is equal to 258.10.73.138.11:00 00 00 00 00 00. I guess a different way to explain it is I want to check if the result contains the exact IP address that I need to inquire about. Here is my code so far:
(@arpResults) = &snmpwalk("$secret\@$gw", "$ipNetToMediaPhysAddress"); foreach $linebuf (@arpResults) { if ($linebuf =~ /\d+\.$oc1\.$oc2\.$oc3\.$oc4\:*/){ print "$linebuf\n"; my $val; ($arpMib, $arpOctetstr) = split(/:/, $linebuf, 2); ($distIndex) = split (/\./,$arpMib, 2); map { $val .= sprintf("%02x",$_) } unpack "CCCCCC", $arpOctetstr; $macFromARP= uc (join(":",unpack("a2 a2 a2 a2 a2 a2",$val))); ($ifNamez)=&snmpget("$secret\@$gw", "$ifName\.$distIndex"); $vlan = $ifNamez; $vlan =~ s/\D//g; print "$arpMib; $distIndex:$ifNamez:-$vlan Value=\t$macFromARP\n +"; }}
This is not working out for me because it still matches ips that have a forth octet begining with "11". Help is greatly appreciated.
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |