Skip to content

Commit

Permalink
Updaed RexExp, Extract IP + Defang IP to use lib
Browse files Browse the repository at this point in the history
  • Loading branch information
h345983745 committed Jun 29, 2019
1 parent 92c0b07 commit 3100ff9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 23 deletions.
14 changes: 1 addition & 13 deletions src/core/operations/DefangIP.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import Operation from "../Operation";

import {IPV4_REGEX, IPV6_REGEX} from "../lib/IP";

/**
* Defang IP operation
Expand Down Expand Up @@ -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");
12 changes: 5 additions & 7 deletions src/core/operations/ExtractIPAddresses.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions src/core/operations/RegularExpression.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 3100ff9

Please sign in to comment.