Here is the code snippet:
def is_tor_ip(ip_address):
# Use TorDNSEL service to check if an IP address is a Tor exit node
tor_dnsel_url = f"https://www.dan.me.uk/torlist/"
try:
with request.urlopen(tor_dnsel_url) as response:
tor_exit_nodes = response.read().decode('utf-8').split('\n')
return ip_address in tor_exit_nodes
except Exception as e:
print(f"Error checking Tor exit node: {e}")
return False
Here is the log from CloudWatch: Error checking Tor exit node: HTTP Error 403: Forbidden
Here are the permissions assigned to the functions Role: AmazonS3FullAccess
AmazonS3ObjectLambdaExecutionRolePolicy
AmazonS3ReadOnlyAccess
AWSLambdaBasicExecutionRole-0d3cae5e-6e55-437d-ad73-5d1546eff3fa
lambda-read-s3
I've tried adding user-agent headers to no avail. I'm not really a programmer just a security guy trying to automate a function to report on Tor IP usage.