0% found this document useful (0 votes)
6 views2 pages

Analyze IP Abuse Confidence Scores

Uploaded by

vecase1048
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

Analyze IP Abuse Confidence Scores

Uploaded by

vecase1048
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

import requests

import pandas as pd
from [Link] import files # Import the files module

def get_abuseipdb_info(api_key, ip_addresses):


url = '[Link]
headers = {
'Key': api_key,
'Accept': 'application/json'
}

results = []

for ip_address in ip_addresses:


params = {'ipAddress': ip_address.strip()}

try:
response = [Link](url, headers=headers, params=params)
response.raise_for_status()

result = [Link]()
[Link](result)
except [Link] as e:
print(f"Error for IP {ip_address}: {e}")

return results

def main():
# Replace 'YOUR_API_KEY' with your actual AbuseIPDB API key
api_key = ''

# Prompt user to upload a CSV file


uploaded = [Link]()
file_name = list([Link]())[0]

# Load IP addresses and domains from the uploaded CSV file


df = pd.read_csv(file_name)
target_ips = df['Source IP'].astype(str).tolist()

# Get AbuseIPDB results


results = get_abuseipdb_info(api_key, target_ips)

# Create lists to store additional data


domains = []
country_codes = []
abuse_confidence_scores = []

for result in results:


# Check if 'domain' key is present in the result
if 'domain' in result['data']:
domain = result['data']['domain']
else:
domain = None

country_code = result['data']['countryCode']
abuse_confidence_score = result['data']['abuseConfidenceScore']

# Append data to the lists


[Link](domain)
country_codes.append(country_code)
abuse_confidence_scores.append(abuse_confidence_score)

# Add new columns to the original DataFrame


df['Domain'] = domains
df['Country Code'] = country_codes
df['Abuse Confidence Score'] = abuse_confidence_scores

# Save the updated DataFrame to the original CSV file


df.to_csv(file_name, index=False)

# Download the modified CSV file using the files module


[Link](file_name)

if __name__ == "__main__":
main()

You might also like