adamZ88 has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regex to match an IP address that is embedded inside of another string
by stevieb (Canon) on Apr 19, 2016 at 22:04 UTC | |
|
Re: Regex to match an IP address that is embedded inside of another string
by GrandFather (Saint) on Apr 19, 2016 at 22:05 UTC | |
by adamZ88 (Beadle) on Apr 19, 2016 at 22:13 UTC | |
by stevieb (Canon) on Apr 19, 2016 at 22:30 UTC | |
by adamZ88 (Beadle) on Apr 20, 2016 at 13:17 UTC | |
by adamZ88 (Beadle) on Apr 19, 2016 at 22:26 UTC | |
|
Re: Regex to match an IP address that is embedded inside of another string
by Anonymous Monk on Apr 19, 2016 at 22:11 UTC |