I'm working on a simple IDS for class. We have to have a rules file that will be used to log certain packets that I capture. The script is capturing packets fine but I'm stuck on how to go about reading the lines in my rule file and then comparing them to information that I get from reading the packets.

My professor said that the rules file should should look something like this:

Source, IP, [ip of desired packet that I want to log] Source, Domain, [the domain name of the desired packet]

Ignoring the brackets, just typing the IP and domain.

And etc where I'll have the source IPs and domains and also the destination IPs and domains of the packets I want to log. The program must be able to take the word "Source" and "IP" (comma separated) and know that I mean compare the IP in the line (from the file) to the IP that I get from

print "Source IP: ", $ip_obj->{src_ip}, "\n";

in my program

How would I go about reading line by line and the telling the program to use this line so I can compare them to the packets I've already captured? Sorry for being vague but this is the best I think I can explain it.

Thanks for reading.


In reply to Reading a Line from a File then Assigning it to a variable by burningredmoon

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.