Hi Experts, I'm sure this will be an easy one for you all and would truely appreciate some help. I am an extreme newbie with Perl, and have been writing a script with the help of a friend. Unfortunately my friend was just shipped overseas to Iraq, and he helped me write the majority of this script and now i'm lost. I have the start of my script working fine, but am stuck at this next peice of the script. My goal is go grep all IP's from a log file, and then count the # of each IP it finds. If 1.2.3.4 is found in the log file twice, I would like it to display 1.2.3.4 and add the # it finds of that IP to my print statement/csv file. I could do this if this was the only function the script had, however the script is doing a lot more than that so I need to incorporate this into the existing script. Below is the script so far. Now I need help with adding the next section to the script, the IP count.
#!/usr/bin/perl -w use strict; my %domains; my @domain_array = qw(ebay.com paypal.com americanbank.com usbank.com +americangreetings.com); my $log_domain; my $host_test; my $host_cmp; my $host; my @bad_domains; my $spf; my $dkim; for (@domain_array) { $domains{$_}{"counter"} = 0; $domains{$_}{"dkim0"} = 0; $domains{$_}{"dkim1"} = 0; $domains{$_}{"dkim2"} = 0; $domains{$_}{"dkim3"} = 0; $domains{$_}{"dkim4"} = 0; $domains{$_}{"spf0"} = 0; $domains{$_}{"spf1"} = 0; $domains{$_}{"spf2"} = 0; $domains{$_}{"spf3"} = 0; $domains{$_}{"spf4"} = 0; } open ($log_domain, "logdata") || die "$!"; while (<$log_domain>) { ($host) = $_ =~ /domain=([\w\.]+?)\s/;#find regex for domain ($spf)= $_ =~ /spf=([0-4])\s/; #find regex for spf1 ($dkim) = $_ = /dkim=([0-4])\s/; # find regex for dkim1 ###IP Regex - I'm assuming the regex for this is --($IP) = $_ =~ /ip=( +([0-1]?[0-9]{1,2}\.)|(2[0-4][0-9]\.)|(25[0-5]\.)){3}(([0-1]?[0-9]{1,2 +})|(2[0-4][0-9])|(25[0-5]))\s/; $host_test = 0; foreach $host_cmp (keys %domains) #pull each key from domains hash { if ($host =~ $host_cmp) # if host equals domain in hash, incriment + counter { $domains{$host}{"counter"}++; $domains{$host}{"spf$spf"}++; $domains{$host}{"dkim$dkim"}++; $host_test = 1; #Test to ensure domain is present } } if ($host_test == 0) #if domain is not in array { push (@bad_domains , $host); } } print "Domain,\"Domain Count\",Dkim0,Dkim1,Dkim2,Dkim3,Dkim4,Spf0,Spf1 +,Spf2,Spf3,Spf4\n"; foreach $host_cmp (keys %domains) { print "$host_cmp,"; print $domains{$host_cmp}{"counter"}.","; print $domains{$host_cmp}{"dkim0"}.","; print $domains{$host_cmp}{"dkim1"}.","; print $domains{$host_cmp}{"dkim2"}.","; print $domains{$host_cmp}{"dkim3"}.","; print $domains{$host_cmp}{"dkim4"}.","; print $domains{$host_cmp}{"spf0"}.","; print $domains{$host_cmp}{"spf1"}.","; print $domains{$host_cmp}{"spf2"}.","; print $domains{$host_cmp}{"spf3"}.","; print $domains{$host_cmp}{"spf4"}."\n"; } print "The total amount of domains that we don't care about is ".($#ba +d_domains+1)."\n"; close ($log_domain);

In reply to IP Parse and Count from logfile by indkebr

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.