View Single Post
Old Dec 19th, 2007, 12:24 PM   #2
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Posts: 1,799
Rep Power: 5 Sane will become famous soon enough
Re: Count number of occourences of a IP address in a log file.

You want something called a hash table. In other languages, this data type has other synonyms. In Perl, it's an "associative array". In Python, it's a "dictionary". Etc etc.

If you plan on using Perl, read up on how to use an associative array. Then you will implement pseudocode that looks something like this:

for each ip address in the log file
    see if the ip address exists in the hash table
    if the ip address does exist
        then increment its value by +1
    if the ip address does not exist
        then make a new entry in the hash table for the ip address
        set its starting value to 1

if any entry in the hash table goes over 1000. then do something about it.

You will also need to think of a way to incorporate time into account, since someone could view your page 1000 times over the span of a month, and your program would consider it an attack.

Unless your log file already flushes daily. Then you're set.
Sane is offline   Reply With Quote