you need to create a post meta with ip value. And check it if ip available in database or not. you need to delete this meta key with value between 39 to 41 minute.
write a function to delete meta key with value in 40th minute. paste This function on single.php
Check ip available in db or not
$query = new WP_Query( 'meta_key=ip&meta_value=".$ip_address );
if ( $query->have_posts()){
//do something to block
}