AbuseIPDB API - проверка IP - 2026 - bash скрипт

Материал из Wiki - Iphoster - the best ever hosting and support. 2005 - 2026
Перейти к:навигация, поиск

AbuseIPDB API - проверка IP - 2026 - bash скрипт

Покажет данные по репутации IP для срока по времени maxAgeInDays=360 дней - ограничение бесплатной версии:

#!/usr/bin/env bash
set -euo pipefail

API_KEY="ТУТ КЛЮЧ API"
BASE_URL="https://api.abuseipdb.com/api/v2"

if [ $# -ge 1 ]; then
  IP="$1"
else
  read -r -p "Enter IP address: " IP
fi

echo "IP: $IP"
echo

RESPONSE=$(curl -s -G "$BASE_URL/check" \
  --data-urlencode "ipAddress=$IP" \
  -d maxAgeInDays=360 \
  -d verbose \
  -H "Key: $API_KEY" \
  -H "Accept: application/json")

python3 -c "
import sys, json
from datetime import datetime, timezone

data = json.load(sys.stdin)
if 'data' not in data:
    print('Error:', data.get('detail', str(data)))
    sys.exit(1)

d = data['data']
reports = d.get('reports', [])

CATEGORIES = {
  1:'DNS Compromise', 2:'DNS Poisoning', 3:'Fraud Orders', 4:'DDoS Attack',
  5:'FTP Brute-Force', 6:'Ping of Death', 7:'Phishing', 8:'Fraud VoIP',
  9:'Open Proxy', 10:'Web Spam', 11:'Email Spam', 12:'Blog Spam',
  13:'VPN IP', 14:'Port Scan', 15:'Hacking', 16:'SQL Injection',
  17:'Spoofing', 18:'Brute-Force', 19:'Bad Web Bot', 20:'Exploited Host',
  21:'Web App Attack'
}

def fmt_ts(ts_str):
    try:
        dt = datetime.fromisoformat(ts_str.replace('Z', '+00:00'))
        now = datetime.now(timezone.utc)
        diff = now - dt
        days = diff.days
        if days < 1:
            hrs = int(diff.total_seconds() // 3600)
            return dt.strftime('%Y-%m-%d %H:%M:%S') + f' ({hrs}h ago)'
        elif days == 1:
            return dt.strftime('%Y-%m-%d %H:%M:%S') + ' (1 day ago)'
        else:
            return dt.strftime('%Y-%m-%d %H:%M:%S') + f' ({days} days ago)'
    except:
        return ts_str

def flag_em(cc):
    if not cc or len(cc) != 2:
        return ''
    return chr(0x1F1E6 + ord(cc[0]) - 65) + chr(0x1F1E6 + ord(cc[1]) - 65)

print(f'Abuse Confidence Score: {d[\"abuseConfidenceScore\"]}%')
print(f'ISP: {d.get(\"isp\", \"N/A\")} ({d.get(\"countryName\", \"N/A\")})')
print(f'Total Reports: {d[\"totalReports\"]} | Distinct Reporters: {d[\"numDistinctUsers\"]}')
print()

if not reports:
    print('No reports found for this IP.')
else:
    for r in reports:
        ts = r['reportedAt']
        comment = r.get('comment', '')
        cat_ids = r.get('categories', [])
        cat_names = ' '.join(CATEGORIES.get(cid, str(cid)) for cid in cat_ids)
        cc = r.get('reporterCountryCode', '')
        rid = r['reporterId']
        cn = r.get('reporterCountryName', '')

        print(f'{flag_em(cc)} Reporter ID {rid} ({cn})\t{fmt_ts(ts)}')
        print(f'Comment: {comment}')
        print(f'Categories: {cat_names}')
        print()
" <<< "$RESPONSE"



https://docs.abuseipdb.com/#introduction
https://www.abuseipdb.com/
×
Реклама
ИКС