I may have a solution. This program checks whether an IP address can create another account based on the specified time limit. The can_create_account
method returns True
if the IP address is allowed to create an account or False
if it’s blocked within the time limit. You can use this as it is, or make any changes if necessary.
import time
class AccountCreationBlocker:
def __init__(self, time_limit=3600):
self.ip_addresses = {}
self.time_limit = time_limit
def can_create_account(self, ip_address):
current_time = time.time()
if ip_address in self.ip_addresses:
last_creation_time = self.ip_addresses[ip_address]
if current_time - last_creation_time < self.time_limit:
return False
else:
self.ip_addresses[ip_address] = current_time
return True
else:
self.ip_addresses[ip_address] = current_time
return True
# Example usage
blocker = AccountCreationBlocker()
ip_address1 = "192.168.1.1"
ip_address2 = "192.168.1.2"
print(blocker.can_create_account(ip_address1)) # Output: True
print(blocker.can_create_account(ip_address1)) # Output: False (within the time limit)
print(blocker.can_create_account(ip_address2)) # Output: True
# Wait for some time
time.sleep(3601) # Sleep for more than the time limit
print(blocker.can_create_account(ip_address1)) # Output: True (time limit expired)
1 post - 1 participant