Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Issue with Net::Frame packages

by WalkingZero (Sexton)
on Jun 01, 2008 at 10:09 UTC ( [id://689534]=perlquestion: print w/replies, xml ) Need Help??

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.

Replies are listed 'Best First'.
Re: Issue with Net::Frame packages
by Anonymous Monk on Jun 01, 2008 at 10:39 UTC
    Try adding some error checking. Example
    sub computeLengths { my $self = shift; if (exists $self->[$__ref]->{IPv4} || exists $self->[$__ref]->{IPv6 +}) { my $ip = $self->[$__ref]->{IPv4} || $self->[$__ref]->{IPv6}; if (exists $self->[$__ref]->{TCP}) { my $tcp = $self->[$__ref]->{TCP}; $tcp->computeLengths; $ip->computeLengths({ payloadLength => $tcp->getLength + $tcp->getPayloadLength, });

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://689534]
Approved by Erez
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2025-11-14 06:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (70 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.