Simple script for filtering out a proxy IP from web traffic.

#!/usr/bin/perl -w

# A script to filter an internal proxy IP in apache logs, plus counting IPs.

open (FH, "access_log") or die ("Open Failed: $!\n");

while (){
$infile = $_;
if ($ip_p = m/(192\.168\.10\.2)\ - - /)
{$ip_proxy += $ip_p};

# Addition: Count all IP's and display sum
if ($ip_a = m/(.*)\ - - /)
{$ip_all += $ip_a};
# End Addition

# Difference between the two.
$ip_diff = $ip_all - $ip_proxy;

# Diff divided by Proxy =~ Ratio
$ip_ratio = $ip_diff / $ip_proxy;

print "Total IP count is: ALL\n";
print "Proxy IP ( count is: Proxy\n";
print "IP without Proxy count is: Diff\n";
print "----------------------------------------------\n";
print " ALL: Proxy: Diff:\n";
printf("%7d %7d %7d\n",$ip_all,$ip_proxy,$ip_diff);
print "\n";
print "The ratio of proxy requests to all other requests is 1:$ip_ratio.\n";
print "\n";

close FH;


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s