import requests
import json
def check_abuse_score(api_key, file_path):
# Defining the api-endpoint
url="https://api.abuseipdb.com/api/v2/check"
headers = {
'Accept': 'application/json',
'Key': api_key
}
# Reading IP addresses from the file
with open(file_path, 'r') as file:
ip_addresses = file.read().splitlines()
# Collecting IP addresses with abuse score greater than 89
high_confidence_ips = []
for ip in ip_addresses:
querystring = {'ipAddress': ip}
response = requests.request(method='GET', url=url, headers=headers, params=querystring)
decoded_response = json.loads(response.text)
# Check if 'data' key is present in the response
if 'data' in decoded_response and 'abuseConfidenceScore' in decoded_response['data']:
abuse_confidence_score = decoded_response['data']['abuseConfidenceScore']
if abuse_confidence_score > 89:
high_confidence_ips.append({'ipAddress': ip, 'abuseConfidenceScore': abuse_confidence_score})
else:
print(f"Error processing IP address {ip}: {decoded_response}")
# Printing the list of IP addresses with abuse score greater than 89
print("IP Addresses with Abuse Confidence Score > 89:")
for entry in high_confidence_ips:
print(f"IP Address: {entry['ipAddress']}, Confidence Score: {entry['abuseConfidenceScore']}")
# Replace 'YOUR_OWN_API_KEY' with your actual API key
api_key = 'Add_your_API'
# Replace 'path/to/your/file.txt' with the actual path to your file containing IP addresses
file_path="/content/List_Ips.txt"
# Calling the function
check_abuse_score(api_key, file_path)