{% extends "base.html" %} {% block title %}API Documentation - IP WHOIS Analyzer Pro{% endblock %} {% block nav_api %}active{% endblock %} {% block extra_css %} {% endblock %} {% block content %}
API Information

Base URL: http://localhost:5000

Format: JSON

Authentication: None (local use)

POST /api/analyze

Analyze a list of IP addresses and return WHOIS information (ASN, owner, country, network).

Request Body:
{
  "ips": "1.1.1.1, 8.8.8.8, 9.9.9.9"
}
Python Example:
import requests

response = requests.post('http://localhost:5000/api/analyze', 
    json={'ips': '1.1.1.1, 8.8.8.8, 9.9.9.9'})

data = response.json()
print(f"Total IPs: {data['stats']['total']}")
for ip_info in data['results']:
    print(f"{ip_info['ip']} -> {ip_info['country']} ({ip_info['asn']})")

POST /api/filter

Filter results by countries, ASNs, or owners.

Python Example:
import requests

# First, analyze
analyze_response = requests.post('http://localhost:5000/api/analyze',
    json={'ips': 'your IP list...'})
results = analyze_response.json()['results']

# Then filter
filter_response = requests.post('http://localhost:5000/api/filter',
    json={
        'results': results,
        'filters': {
            'countries': ['CN', 'RU'],
            'asns': ['AS4134']
        }
    })

filtered = filter_response.json()['filtered']
print(f"Filtered: {len(filtered)} IPs")

POST /api/export/ipset

Generate IPSet rules with timeout (default 24 hours).

Python Example:
import requests

response = requests.post('http://localhost:5000/api/export/ipset',
    json={
        'ips': ['1.1.1.1', '8.8.8.8'],
        'timeout': 43200  # 12 hours
    })

rules = response.text
with open('block_ips.sh', 'w') as f:
    f.write(rules)
print("Saved to block_ips.sh")

POST /api/export/iptables

Generate iptables DROP rules for INPUT and FORWARD chains.

POST /api/export/nginx

Generate Nginx deny directives.

POST /api/export/apache

Generate Apache deny rules (.htaccess or VirtualHost).

POST /api/export/firewalld

Generate Firewalld rich rules.

POST /api/export/mikrotik

Generate MikroTik RouterOS commands (address-list + firewall filter).

POST /api/export/cidr

Export unique CIDR network blocks.

POST /api/export/csv

Export data in CSV format with automatic download.

Complete Workflow Example

Full example: analyze → filter → export to MikroTik

import requests

BASE_URL = 'http://localhost:5000'

# 1. Analyze IPs from log file
with open('/var/log/attacks.log', 'r') as f:
    log_content = f.read()

response = requests.post(f'{BASE_URL}/api/analyze',
    json={'ips': log_content})

data = response.json()
results = data['results']
print(f"Analyzed: {len(results)} IPs")

# 2. Filter China and Russia only
filter_response = requests.post(f'{BASE_URL}/api/filter',
    json={
        'results': results,
        'filters': {'countries': ['CN', 'RU']}
    })

filtered = filter_response.json()['filtered']
ips_to_block = [item['ip'] for item in filtered]

# 3. Generate MikroTik rules
mikrotik_response = requests.post(f'{BASE_URL}/api/export/mikrotik',
    json={'ips': ips_to_block})

# 4. Save to file
with open('block_cn_ru.rsc', 'w') as f:
    f.write(mikrotik_response.text)

print(f"Generated rules for {len(ips_to_block)} IPs")
{% endblock %} {% block extra_scripts %} {% endblock %} {% block page_script %} {% endblock %}