J
jlm33990
I'm trying to read a file which is sorted by field 3 which is an ip
number with the port number added to the end. Each new record starts
with the timestamp.
Here's part of the file so you get the right idea...
11:03:36.315447 IP 12.101.124.3.14459 > mandy2.me.com.smtp: S
2740947399:27
40947399(0) win 65535 <mss 1380,nop,nop,sackOK>
11:03:39.203578 IP 12.101.124.3.14459 > mandy2.me.com.smtp: S
2740947399:27
40947399(0) win 65535 <mss 1380,nop,nop,sackOK>
11:03:45.216961 IP 12.101.124.3.14459 > mandy2.me.com.smtp: S
2740947399:27
40947399(0) win 65535 <mss 1380,nop,nop,sackOK>
11:18:56.302252 IP 12.101.124.3.16527 > mandy2.me.com.smtp: S
222122110:222
122110(0) win 65535 <mss 1380,nop,nop,sackOK>
11:18:59.344184 IP 12.101.124.3.16527 > mandy2.me.com.smtp: S
222122110:222
122110(0) win 65535 <mss 1380,nop,nop,sackOK>
11:29:42.569311 IP 12.102.102.180.36150 > mandy2.me.com.smtp: S
416085218:4
16085218(0) win 65535 <mss 1380,nop,nop,sackOK>
11:29:48.527397 IP 12.102.102.180.36150 > mandy2.me.com.smtp: S
416085218:4
16085218(0) win 65535 <mss 1380,nop,nop,sackOK>
10:52:36.447595 IP 12.103.253.170.10434 > mandy2.me.com.smtp: . ack 1
win 6
4512
10:53:25.046979 IP 12.103.253.170.10434 > mandy2.me.com.smtp: . ack 258
win
64256
For each unique ip number (with port not included) I want to print a
summary showing ip# and how many records for that number.
here';s the code that I've been struggling with.......
#!/usr/bin/perl
open(REPORT,">apost.report")|| die "cannot create report $!\n";
print REPORT " apost.report\n";
print REPORT "\n";
print REPORT "IP# #packets
\n";
print REPORT
"------------------------------------------------------------------
----------\n";
format REPORT=
@<<<<<<<<<<<<<<<<<<<<<@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<@<<<<<<<<<<<<<<<<<<<<<<<<
$ip,$hits,$lastip
..
$lastip='12.101.124.3';
$hits=0;
$first="y";
@ifile=`cat sorted`;
foreach(@ifile) {
($time,$m,$ip1,$t) = split(/ /,$_);
($ip2,$ip3,$ip4,$ip5,$ip6) = split(/\./,$ip1);
$ip="$ip2\.$ip3\.$ip4\.$ip5";
if ($ip == $lastip) {
$hits++;
}
else {
write REPORT,"\n";
$lastip=$ip;
$hits=0;
}
}
print REPORT
"------------------------------------------------------------------
------\n";
close(REPORT);
Needless to say - it does'nt work (but i'm close) - can anyone point
out the flaw please?
Thanks - jim
number with the port number added to the end. Each new record starts
with the timestamp.
Here's part of the file so you get the right idea...
11:03:36.315447 IP 12.101.124.3.14459 > mandy2.me.com.smtp: S
2740947399:27
40947399(0) win 65535 <mss 1380,nop,nop,sackOK>
11:03:39.203578 IP 12.101.124.3.14459 > mandy2.me.com.smtp: S
2740947399:27
40947399(0) win 65535 <mss 1380,nop,nop,sackOK>
11:03:45.216961 IP 12.101.124.3.14459 > mandy2.me.com.smtp: S
2740947399:27
40947399(0) win 65535 <mss 1380,nop,nop,sackOK>
11:18:56.302252 IP 12.101.124.3.16527 > mandy2.me.com.smtp: S
222122110:222
122110(0) win 65535 <mss 1380,nop,nop,sackOK>
11:18:59.344184 IP 12.101.124.3.16527 > mandy2.me.com.smtp: S
222122110:222
122110(0) win 65535 <mss 1380,nop,nop,sackOK>
11:29:42.569311 IP 12.102.102.180.36150 > mandy2.me.com.smtp: S
416085218:4
16085218(0) win 65535 <mss 1380,nop,nop,sackOK>
11:29:48.527397 IP 12.102.102.180.36150 > mandy2.me.com.smtp: S
416085218:4
16085218(0) win 65535 <mss 1380,nop,nop,sackOK>
10:52:36.447595 IP 12.103.253.170.10434 > mandy2.me.com.smtp: . ack 1
win 6
4512
10:53:25.046979 IP 12.103.253.170.10434 > mandy2.me.com.smtp: . ack 258
win
64256
For each unique ip number (with port not included) I want to print a
summary showing ip# and how many records for that number.
here';s the code that I've been struggling with.......
#!/usr/bin/perl
open(REPORT,">apost.report")|| die "cannot create report $!\n";
print REPORT " apost.report\n";
print REPORT "\n";
print REPORT "IP# #packets
\n";
print REPORT
"------------------------------------------------------------------
----------\n";
format REPORT=
@<<<<<<<<<<<<<<<<<<<<<@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<@<<<<<<<<<<<<<<<<<<<<<<<<
$ip,$hits,$lastip
..
$lastip='12.101.124.3';
$hits=0;
$first="y";
@ifile=`cat sorted`;
foreach(@ifile) {
($time,$m,$ip1,$t) = split(/ /,$_);
($ip2,$ip3,$ip4,$ip5,$ip6) = split(/\./,$ip1);
$ip="$ip2\.$ip3\.$ip4\.$ip5";
if ($ip == $lastip) {
$hits++;
}
else {
write REPORT,"\n";
$lastip=$ip;
$hits=0;
}
}
print REPORT
"------------------------------------------------------------------
------\n";
close(REPORT);
Needless to say - it does'nt work (but i'm close) - can anyone point
out the flaw please?
Thanks - jim