import requests
import pandas as pd
import smtplib
from email.mime.text import MIMEText
# Function to fetch threat intelligence data
def fetch_threat_data(api_url):
response = requests.get(api_url)
if response.status_code == 200:
return response.json()
else:
print(f"Failed to fetch data from {api_url}")
return None
# Function to analyze threats and generate a report
def analyze_threats(data):
threats = pd.DataFrame(data)
report = threats.describe() # Basic statistical summary
return report
# Function to send email alerts
def send_alert(report):
sender = "your_email@example.com"
recipients = ["recipient@example.com"]
subject = "Threat Intelligence Report"
body = report.to_string()
msg = MIMEText(body)
msg['Subject'] = subject
msg['From'] = sender
msg['To'] = ", ".join(recipients)
with smtplib.SMTP('smtp.example.com', 587) as server:
server.starttls()
server.login(sender, "your_password")
server.sendmail(sender, recipients, msg.as_string())
# Main function
def main():
# Example API endpoints (replace with actual threat intelligence APIs)
api_urls = [
"https://api.example.com/threats",
"https://api.anotherexample.com/threats"
]
all_data = []
for api_url in api_urls:
data = fetch_threat_data(api_url)
if data:
all_data.extend(data)
if all_data:
report = analyze_threats(all_data)
print(report)
send_alert(report)
if __name__ == "__main__":
main()