Skip to content

Commit 3c53f97

Browse files
authored
Get Range of Ip addresses (#1171)
* Create GetIPRange * Delete Flow Actions/GetIPRange/GetIPRange * Create getIPRange.js * Create readme.md
1 parent 472a371 commit 3c53f97

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
(function execute(inputs, outputs) {
2+
3+
outputs.ipoutput = getIpsFromRange(ipToHex((transformIP(inputs.firstip))), ipToHex(transformIP(inputs.secondip)));
4+
5+
6+
//transform the IP Address into a decimal number. Each octet will need to converted to a decimal first and then added back together
7+
function transformIP(ip) {
8+
var d = ip.split(".");
9+
var num = 0;
10+
num += Number(d[0]) * Math.pow(256, 3);
11+
num += Number(d[1]) * Math.pow(256, 2);
12+
num += Number(d[2]) * Math.pow(256, 1);
13+
num += Number(d[3]);
14+
return num;
15+
}
16+
//Transform Decimal number into a HEX value, the decimal number will be to large to deal with. HEX will shorten it an make it easier to deal with. HEX Value Example> 817EB263 or 0A0A0A0A
17+
function ipToHex(ipList) {
18+
var dec = ipList.toString().split(''),
19+
sum = [],
20+
hex = [],
21+
i, s;
22+
while (dec.length) {
23+
s = 1 * dec.shift();
24+
for (i = 0; s || i < sum.length; i++) {
25+
s += (sum[i] || 0) * 10;
26+
sum[i] = s % 16;
27+
s = (s - sum[i]) / 16;
28+
}
29+
}
30+
while (sum.length) {
31+
hex.push(sum.pop().toString(16));
32+
}
33+
return "0x" + hex.join('').toString();
34+
}
35+
//Take the HEX Values and transform them back into an IP Address by shifting the bits right as seen in oc4,oc3,oc2 below. This will loop through untill it reaches the final HEX value converting along the way. it will. then push into an array
36+
function getIpsFromRange(hex1, hex2) {
37+
var ipArr = [];
38+
for (var i = hex1; i < hex2; i++) {
39+
var oc4 = (i >> 24) & 255;
40+
var oc3 = (i >> 16) & 255;
41+
var oc2 = (i >> 8) & 255;
42+
var oc1 = i & 255;
43+
gs.debug("IP ADDRESSES: " + oc4 + "." + oc3 + "." + oc2 + "." + oc1);
44+
ipArr.push(oc4 + "." + oc3 + "." + oc2 + "." + oc1 + "\\n");
45+
}
46+
gs.debug("ARRRAY: " + ipArr);
47+
return ipArr;
48+
}
49+
})(inputs, outputs);

Flow Actions/GetIPRange/readme.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Overview
2+
To be used for getting all the IP Addresses within a given range eg 192.168.0.1 - 192.168.0.255. This will print everything between those IP ADDRESSES
3+
4+
Inputs
5+
inputs.firstip - First ipaddress in the range
6+
inputs.secondip - Second ip address in the range
7+
8+
Script Step
9+
Create a script step with the code provided to look up a range of ip address
10+
11+
Outputs
12+
returns all ip addresses in a given range

0 commit comments

Comments
 (0)