I am playing around with the PCAP modules and was happily gathering data on machines on the network. But I was putting them into a HoH, keyed off the Ethernet MAC address. Like this:
$hash{MAC}{IP}
$hash{MAC}{Port}
$hash{MAC}{# of Packets}
etc
It's not hard to see that this means that I can't see which IPs used which protocols, or how many packets were used for each protocol.
The obvious answer for the example above is: use a HoHoHoH
$hash{MAC}{IP}{Port}{#Packets}
but there are actually a few more variables involved, such as destination IP by source IP, destination port by source IP, etc . So I might be tempted by a data structure like this:
$hash{MAC}{IP}{Port}{Destination IP}{Port}{#Packets}
Obviously there are a few problems with this solution, including the fact that I might have to iterate over lots of sub-hashes, and it looks inelegant.
So what would you recommend? Should I maintain half a dozen separate hashes and update each one (possibly via a subroutine)? Should I create an object that will return data when called by methods like $obj->ports_by_ip($ip)?
____________________
Jeremy
I didn't believe in evil until I dated it.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.