Created
September 26, 2011 10:38
-
-
Save keiya/1241996 to your computer and use it in GitHub Desktop.
This script parses the apache logfile from STDIN.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/perl | |
| # | |
| # by Keiya Chinen | |
| use strict; | |
| use warnings; | |
| my %hosts; | |
| while (my $line = <STDIN>) { | |
| $line =~ m/^.+?:80 ([\d\.]+)/; | |
| $hosts{$1}{'cnt'}++; | |
| } | |
| foreach my $k (keys %hosts) { | |
| my $host = gethostbyaddr(pack("C4", split(/\./, $k)), 2); | |
| $host = $k if not defined $host; | |
| if ($host =~ m/\.ne(?:t|\.\w+?)$/) { | |
| print "Provider\t$host ($k)\n"; | |
| } | |
| elsif ($host =~ m/\.go(?:v|\.\w+?)$/) { | |
| print "Government\t$host ($k)\n"; | |
| } | |
| elsif ($host =~ m/\.co(?:m|\.\w+?)$/) { | |
| print "Company\t$host ($k)\n"; | |
| } | |
| elsif ($host =~ m/\.or(?:g|\.\w+?)$/) { | |
| print "Organization\t$host ($k)\n"; | |
| } | |
| elsif ($host =~ m/\.ed(?:u|\w+?)$/) { | |
| print "Education\t$host ($k)\n"; | |
| } | |
| elsif ($host =~ m/\.ac\.jp$/) { | |
| print "Univ(JP)\t$host ($k)\n"; | |
| } | |
| elsif ($host =~ m/\.mil$/) { | |
| print "MILITARY\t$host ($k)\n"; | |
| } | |
| elsif ($host =~ m/\.jp$/) { | |
| print "Japan\t$host ($k)\n"; | |
| } | |
| else { | |
| print "Unknown\t$host ($k)\n"; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment