Automate Threat Intel Lookups With Python: Check Any IP Against AbuseIPDB


You found a strange IP in your logs. Is it a real attacker, or just a misconfigured bot? Checking one IP by hand is fine. Checking fifty is a chore. So let’s automate it: a Python script that queries AbuseIPDB — a free community database of reported abusive IPs — and gives you a verdict in seconds.

Why AbuseIPDB?

AbuseIPDB collects reports from thousands of admins: brute-force attempts, port scans, spam, botnet activity. Each IP gets an abuse confidence score from 0–100 based on how often and how recently it was reported. A score of 90 from yesterday’s reports means something; a score of 0 with no reports means nothing yet — not “safe”, just unreported.

Get a Free API Key

Sign up at abuseipdb.com and grab a free API key (1,000 checks per day — plenty for personal use). Keep it out of your code: store it in an environment variable, never hardcoded and never committed to a public repo.

export ABUSEIPDB_KEY="your-key-here"

The Script

import os
import requests
API_KEY = os.environ.get("ABUSEIPDB_KEY")
URL = "https://api.abuseipdb.com/api/v2/check"
def check_ip(ip: str):
headers = {"Key": API_KEY, "Accept": "application/json"}
params = {"ipAddress": ip, "maxAgeInDays": 90, "verbose": ""}
r = requests.get(URL, headers=headers, params=params, timeout=15)
r.raise_for_status()
data = r.json()["data"]
return {
"ip": data["ipAddress"],
"score": data["abuseConfidenceScore"],
"country": data["countryCode"],
"reports": data["totalReports"],
"last_reported": data["lastReportedAt"],
}
def verdict(result):
score = result["score"]
if score >= 75:
return "BLOCK — high-confidence abuser"
if score >= 25:
return "SUSPICIOUS — investigate before blocking"
return "CLEAN/UNREPORTED — keep watching, don't over-trust"
if __name__ == "__main__":
for ip in ["45.148.10.105", "8.8.8.8"]:
res = check_ip(ip)
print(f"{res['ip']} ({res['country']}): score {res['score']}, {res['reports']} reports, last {res['last_reported']}")
print(" Verdict:", verdict(res))

Using It on Your Own Logs

Feed the script IPs from your own logs — for example, the top failed-login IPs you found with the grep/awk pipeline from our Linux post. The output turns a raw list of addresses into a prioritized blocklist: block the 90s, investigate the 40s, ignore the 0s.

Defensive Rules

  • Only look up IPs from your own systems. Don’t run other people’s traffic through threat intel APIs.
  • Don’t auto-block on score alone. A shared VPN or NAT exit can carry one abuser’s score for thousands of innocent users. High score = block with confidence; medium score = investigate first.
  • Respect rate limits. The free tier allows 1,000 checks a day — cache results and skip IPs you’ve already checked.
  • Scores decay. An IP reported six months ago and quiet since is not the same threat as one reported this morning — that’s why we set maxAgeInDays to 90.

You just built a tiny threat-intelligence pipeline. Connect it to your log analysis, and your home server starts defending itself like a professional one.

Comments

Popular Posts