diff --git a/src/core/operations/ExtractIPAddresses.mjs b/src/core/operations/ExtractIPAddresses.mjs
index b74ec8fe..f169e340 100644
--- a/src/core/operations/ExtractIPAddresses.mjs
+++ b/src/core/operations/ExtractIPAddresses.mjs
@@ -21,7 +21,7 @@ class ExtractIPAddresses extends Operation {
this.name = "Extract IP addresses";
this.module = "Regex";
- this.description = "Extracts all IPv4 and IPv6 addresses.
Warning: Given a string 1.2.3.4.5.6.7.8, this will match 1.2.3.4 and 5.6.7.8 so always check the original input!";
+ this.description = "Extracts all IPv4 and IPv6 addresses.
When 'Include defanged' is enabled, addresses defanged with [.] (IPv4) or [:] (IPv6) are also extracted, including partial defangs (e.g. 192.168[.]1.1). Matches are returned as-is; chain Fang IP Addresses after if you need clean addresses. With 'Sort' enabled, defanged matches sort lexicographically after the plain-IP group.
Warning: Given a string 1.2.3.4.5.6.7.8, this will match 1.2.3.4 and 5.6.7.8 so always check the original input!";
this.inputType = "string";
this.outputType = "string";
this.args = [
@@ -54,6 +54,11 @@ class ExtractIPAddresses extends Operation {
name: "Unique",
type: "boolean",
value: false
+ },
+ {
+ name: "Include defanged",
+ type: "boolean",
+ value: false
}
];
}
@@ -64,7 +69,13 @@ class ExtractIPAddresses extends Operation {
* @returns {string}
*/
run(input, args) {
- const [includeIpv4, includeIpv6, removeLocal, displayTotal, sort, unique] = args,
+ const [includeIpv4, includeIpv6, removeLocal, displayTotal, sort, unique, includeDefanged] = args,
+
+ // Defang-aware separator patterns. When includeDefanged is false these
+ // collapse to the original literal separators, so the regex behaviour
+ // is byte-for-byte identical to the pre-change op.
+ dotSep = includeDefanged ? "(?:\\.|\\[\\.\\])" : "\\.",
+ colonSep = includeDefanged ? "(?::|\\[:\\])" : ":",
// IPv4 decimal groups can have values 0 to 255. To construct a regex the following sub-regex is reused:
ipv4DecimalByte = "(?:25[0-5]|2[0-4]\\d|1?[0-9]\\d|\\d)",
@@ -74,13 +85,16 @@ class ExtractIPAddresses extends Operation {
lookBehind = "(?