diff --git a/src/core/operations/DefangIP.mjs b/src/core/operations/DefangIP.mjs index 03bfc6da1..9acaebce5 100644 --- a/src/core/operations/DefangIP.mjs +++ b/src/core/operations/DefangIP.mjs @@ -5,7 +5,7 @@ */ import Operation from "../Operation"; - +import {IPV4_REGEX, IPV6_REGEX} from "../lib/IP"; /** * Defang IP operation @@ -50,15 +50,3 @@ class DefangIP extends Operation { } export default DefangIP; - - -/** - * IPV4 regular expression - */ -const IPV4_REGEX = new RegExp("(?:(?:\\d|[01]?\\d\\d|2[0-4]\\d|25[0-5])\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d\\d|\\d)(?:\\/\\d{1,2})?", "g"); - - -/** - * IPV6 regular expression - */ -const IPV6_REGEX = new RegExp("((?=.*::)(?!.*::.+::)(::)?([\\dA-Fa-f]{1,4}:(:|\\b)|){5}|([\\dA-Fa-f]{1,4}:){6})((([\\dA-Fa-f]{1,4}((?!\\3)::|:\\b|(?![\\dA-Fa-f])))|(?!\\2\\3)){2}|(((2[0-4]|1\\d|[1-9])?\\d|25[0-5])\\.?\\b){4})", "g"); diff --git a/src/core/operations/ExtractIPAddresses.mjs b/src/core/operations/ExtractIPAddresses.mjs index 1cca2098d..3953e21a9 100644 --- a/src/core/operations/ExtractIPAddresses.mjs +++ b/src/core/operations/ExtractIPAddresses.mjs @@ -6,7 +6,7 @@ import Operation from "../Operation"; import { search } from "../lib/Extract"; - +import {IPV4_REGEX, IPV6_REGEX} from "../lib/IP"; /** * Extract IP addresses operation */ @@ -53,17 +53,15 @@ class ExtractIPAddresses extends Operation { * @returns {string} */ run(input, args) { - const [includeIpv4, includeIpv6, removeLocal, displayTotal] = args, - ipv4 = "(?:(?:\\d|[01]?\\d\\d|2[0-4]\\d|25[0-5])\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d\\d|\\d)(?:\\/\\d{1,2})?", - ipv6 = "((?=.*::)(?!.*::.+::)(::)?([\\dA-F]{1,4}:(:|\\b)|){5}|([\\dA-F]{1,4}:){6})((([\\dA-F]{1,4}((?!\\3)::|:\\b|(?![\\dA-F])))|(?!\\2\\3)){2}|(((2[0-4]|1\\d|[1-9])?\\d|25[0-5])\\.?\\b){4})"; + const [includeIpv4, includeIpv6, removeLocal, displayTotal] = args; let ips = ""; if (includeIpv4 && includeIpv6) { - ips = ipv4 + "|" + ipv6; + ips = IPV4_REGEX.source + "|" + IPV6_REGEX.source; } else if (includeIpv4) { - ips = ipv4; + ips = IPV4_REGEX.source; } else if (includeIpv6) { - ips = ipv6; + ips = IPV6_REGEX.source; } if (ips) { diff --git a/src/core/operations/RegularExpression.mjs b/src/core/operations/RegularExpression.mjs index dd183deff..d8afe9625 100644 --- a/src/core/operations/RegularExpression.mjs +++ b/src/core/operations/RegularExpression.mjs @@ -8,7 +8,7 @@ import XRegExp from "xregexp"; import Operation from "../Operation"; import Utils from "../Utils"; import OperationError from "../errors/OperationError"; - +import {IPV4_REGEX, IPV6_REGEX} from "../lib/IP"; /** * Regular expression operation */ @@ -37,11 +37,11 @@ class RegularExpression extends Operation { }, { name: "IPv4 address", - value: "(?:(?:\\d|[01]?\\d\\d|2[0-4]\\d|25[0-5])\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d\\d|\\d)(?:\\/\\d{1,2})?" + value: IPV4_REGEX.source }, { name: "IPv6 address", - value: "((?=.*::)(?!.*::.+::)(::)?([\\dA-Fa-f]{1,4}:(:|\\b)|){5}|([\\dA-Fa-f]{1,4}:){6})((([\\dA-Fa-f]{1,4}((?!\\3)::|:\\b|(?![\\dA-Fa-f])))|(?!\\2\\3)){2}|(((2[0-4]|1\\d|[1-9])?\\d|25[0-5])\\.?\\b){4})" + value: IPV6_REGEX.source }, { name: "Email address",