|
| 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); |
0 commit comments