http://www.perlmonks.org?node_id=689534

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

Hello, I had posted this code at the end of my discussion in ARP Lookups and at the time of posting the code worked flawlessly. Went to run it today and I'm getting:
Can't call method "opCode" on an undefined value at ./arp2.pl line 46.

If I step it back a level just to the ref of $r->ref->{ARP} there is nothing there. However if I go back and do a r->print or if I unpack the raw data, I can see the ARP layer plain as day. I supposed I could use ->print and regex my output, but the modules i'm using shouldn't require me to do that. Any ideas? Code Below:

#!/usr/bin/perl use Net::ARP; use Net::Netmask; use Net::Frame::Simple; use Net::Frame::Dump::Online; my $dev= "eth1"; $ifconf= `ifconfig $dev`; $ifconf=~ /\d+\.\d+\.\d+\.\d+/; $ipdec= $&; $ifconf=~ /Mask:\d+\.\d+\.\d+\.\d+/; $nmaskdec= $&; $nmaskdec=~s/Mask://; my $netblock= $ipdec . ":" . $nmaskdec ; $netmask=new Net::Netmask ($netblock); my @iprange = $netmask->enumerate; $arpDump=Net::Frame::Dump::Online->new( dev => $dev, filter => 'arp'); $arpDump->start; my %livehosts; my $reply; $counter=0; while ($counter<3){ for $ipts (@iprange){ Net::ARP::send_packet($dev,$ipdec,$ipts,"00:18:de:34:8e:7b","f +f:ff:ff:ff:ff:ff","request"); } until ($arpDump->timeout){ if ($next=$arpDump->next){ my $r=Net::Frame::Simple->newFromDump($next); $opc=$r->ref->{ARP}->opCode; next unless $opc == 2; $livehosts{$r->ref->{ARP}->srcIp}=$r->ref->{ARP}->src; } } $arpDump->timeoutReset; $counter++; } foreach $key (keys %livehosts){ print "IP Address $key is up with mac of $livehosts{$key} \n"; } $arpDump->stop;


UPDATE: Arg , what a total waste of time. I went and reloaded Net::Frame from CPAN and now it works fine. Sorry, folks.