Implementation:0xKoda WireMCP ip regex extraction
| Knowledge Sources | |
|---|---|
| Domains | Security, Threat_Detection, Pattern_Matching |
| Last Updated | 2026-10-28 00:00 GMT |
Overview
Concrete tool for extracting IPv4 addresses from unstructured text using a regex pattern, implemented as a reusable pattern within the `check_threats` and `check_ip_threats` tool handlers.
Description
The IP regex extraction pattern applies `/\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/` line-by-line to the raw URLhaus blacklist text body, collecting and deduplicating all matched IPv4 addresses into a `Set`. The regex matches standard dotted-quad IPv4 notation with word boundaries. This is a user-defined pattern (not a library API) that transforms the unstructured blacklist dump into a queryable array of IPs.
Usage
Use this pattern when you need to extract IPv4 addresses from any unstructured text feed (threat intelligence lists, log files, etc.) for set-intersection operations.
Code Reference
Source Location
- Repository: WireMCP
- File: index.js
- Lines: L216-223 (check_threats), L269-276 (check_ip_threats)
Signature
const ipRegex = /\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/;
const urlhausData = [...new Set(
response.data.split('\n')
.map(line => {
const match = line.match(ipRegex);
return match ? match[0] : null;
})
.filter(ip => ip)
)];
Import
// No import needed — RegExp is a built-in JavaScript global
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| text | string | Yes | Raw text containing zero or more IPv4 addresses (e.g., URLhaus response body) |
| ipRegex | RegExp | No | Hardcoded to `/\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/` |
Outputs
| Name | Type | Description |
|---|---|---|
| urlhausData | string[] | Deduplicated array of IPv4 address strings |
Usage Examples
Extract IPs from URLhaus Response
const response = await axios.get('https://urlhaus.abuse.ch/downloads/text/');
const ipRegex = /\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/;
const urlhausData = [...new Set(
response.data.split('\n')
.map(line => {
const match = line.match(ipRegex);
return match ? match[0] : null;
})
.filter(ip => ip)
)];
console.error(`Extracted ${urlhausData.length} unique blacklist IPs`);
Extract IPs from Arbitrary Text
const logText = `Connection from 192.168.1.50 to 10.0.0.1\nBlocked: 172.16.0.5`;
const ipRegex = /\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/;
const ips = [...new Set(
logText.split('\n')
.map(line => line.match(ipRegex)?.[0])
.filter(ip => ip)
)];
// => ['192.168.1.50', '10.0.0.1', '172.16.0.5']