---
name: extract_ip_addresses
kind: function
lang: py
domain: cybersecurity
version: "1.0.0"
purity: pure
signature: "def extract_ip_addresses(text: str) -> list[dict]"
description: "Extrae direcciones IPv4 e IPv6 validas de un texto, con offsets start/end. Filtra candidatos invalidos via ipaddress (rechaza 999.999.999.999 y similares). No distingue privadas de publicas — el filtrado de relevancia es del caller."
tags: [ioc, ip, ipv4, ipv6, regex, extract, cybersecurity, python]
uses_functions: []
uses_types: []
returns: []
returns_optional: false
error_type: ""
imports: [re, ipaddress]
params:
  - name: text
    desc: "string de texto del que extraer IPs"
output: "lista de dicts con {value, start, end, type='ip_address'} por cada IP encontrada"
tested: true
tests:
  - "IPv4 valida y rangos limite"
  - "IPv4 invalida (>255 octeto) descartada"
  - "IPv6 forma completa y comprimida"
  - "IPv6 invalida descartada"
  - "Texto sin IPs"
test_file_path: "python/functions/cybersecurity/tests/test_extract_iocs.py"
file_path: "python/functions/cybersecurity/extract_ip_addresses.py"
---

## Ejemplo

```python
extract_ip_addresses("Server 192.168.1.1 talks to 8.8.8.8")
# [{"value": "192.168.1.1", "start": 7, "end": 18, "type": "ip_address"},
#  {"value": "8.8.8.8", "start": 28, "end": 35, "type": "ip_address"}]

extract_ip_addresses("not an IP: 999.999.999.999")
# []
```

## Notas

Usa `ipaddress.IPv4Address` / `IPv6Address` para validacion estructural — descarta `999.999.999.999` y otras combinaciones sintacticamente plausibles pero invalidas. IPs privadas (10/8, 172.16/12, 192.168/16) se extraen igual; el filtrado de relevancia es responsabilidad del caller. Pure — solo regex compilado y `ipaddress`, sin red ni disco.
