wordpress count link clicks by ip address

What would you do if the user uses a proxy and randomizes his IP address? There are numerous browser plugins to simplify that to a click of a button to download multiple times. The same goes for cookies. Aside from that you are trying to collect data that allows to identify users, which is illegal in lots of countries.

What (could) work much better is a disposable hash that you add as post meta data. Example that adds such a hash during publishing a post – in this case the md5 hashed post date as UNIX time stamp:

add_action( 'draft_to_publish', function( \WP_Post $post )
{
    add_post_meta( 
        $post->ID, 
        'download_hash', 
        md5( date( 'U', $post->post_date ), 
        true 
    );
} );

(You can construct your hash however you want).

Then, when a user downloads a file, simply set a user meta value with that hash as key and a value of 1/true/foo. Upon download, you just check if the current download_hash is already a user meta value and then can deny the download.

To implement a counter, you would simply add another attachment meta value named download_users where you save an array of user IDs. Done.