Skip to content

Commit a616e46

Browse files
author
jb30795
committed
Handling of /24 ranges
1 parent 752ce78 commit a616e46

File tree

1 file changed

+39
-15
lines changed

1 file changed

+39
-15
lines changed

src/core/operations/IPv6TransitionAddresses.mjs

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class IPv6TransitionAddresses extends Operation {
1919

2020
this.name = "IPv6 Transition Addresses";
2121
this.module = "Default";
22-
this.description = "Converts IPv4 addresses to their IPv6 Transition addresses. IPv6 Transition addresses can also be converted back into their original IPv4 address. MAC addresses can also be converted into the EUI-64 format, this can them be appended to your IPv6 /64 range to obtain a full /128 address.<br><br>Transition technologies enable translation between IPv4 and IPv6 addresses or tunneling to allow traffic to pass through the incompatible network, allowing the two standards to coexist.<br><br>Remove headers to easily copy out results.";
22+
this.description = "Converts IPv4 addresses to their IPv6 Transition addresses. IPv6 Transition addresses can also be converted back into their original IPv4 address. MAC addresses can also be converted into the EUI-64 format, this can them be appended to your IPv6 /64 range to obtain a full /128 address.<br><br>Transition technologies enable translation between IPv4 and IPv6 addresses or tunneling to allow traffic to pass through the incompatible network, allowing the two standards to coexist.<br><br>Only /24 ranges and currently handled. Remove headers to easily copy out results.";
2323
this.infoURL = "https://wikipedia.org/wiki/IPv6_transition_mechanism";
2424
this.inputType = "string";
2525
this.outputType = "string";
@@ -62,7 +62,7 @@ class IPv6TransitionAddresses extends Operation {
6262
/**
6363
* Function converts IPv4 to IPv6 Transtion address
6464
*/
65-
function ipTransition(input) {
65+
function ipTransition(input, range) {
6666
let output = "";
6767
const HEXIP = input.split(".");
6868

@@ -72,32 +72,51 @@ class IPv6TransitionAddresses extends Operation {
7272
if (!args[1]) {
7373
output += "6to4: ";
7474
}
75-
output += "2002:" + hexify(HEXIP[0]) + hexify(HEXIP[1]) + ":" + hexify(HEXIP[2]) + hexify(HEXIP[3]) + "::/48\n";
75+
output += "2002:" + hexify(HEXIP[0]) + hexify(HEXIP[1]) + ":" + hexify(HEXIP[2]);
76+
if (range) {
77+
output += "00::/40\n";
78+
} else {
79+
output += hexify(HEXIP[3]) + "::/48\n";
80+
}
7681

7782
/**
7883
* Mapped
7984
*/
8085
if (!args[1]) {
8186
output += "IPv4 Mapped: ";
8287
}
83-
output += "::ffff:" + hexify(HEXIP[0]) + hexify(HEXIP[1]) + ":" + hexify(HEXIP[2]) + hexify(HEXIP[3]) + "\n";
88+
output += "::ffff:" + hexify(HEXIP[0]) + hexify(HEXIP[1]) + ":" + hexify(HEXIP[2]);
89+
if (range) {
90+
output += "00/120\n";
91+
} else {
92+
output += hexify(HEXIP[3]) + "\n";
93+
}
8494

8595
/**
8696
* Translated
8797
*/
8898
if (!args[1]) {
8999
output += "IPv4 Translated: ";
90100
}
91-
output += "::ffff:0:" + hexify(HEXIP[0]) + hexify(HEXIP[1]) + ":" + hexify(HEXIP[2]) + hexify(HEXIP[3]) + "\n";
101+
output += "::ffff:0:" + hexify(HEXIP[0]) + hexify(HEXIP[1]) + ":" + hexify(HEXIP[2]);
102+
if (range) {
103+
output += "00/120\n";
104+
} else {
105+
output += hexify(HEXIP[3]) + "\n";
106+
}
92107

93108
/**
94109
* Nat64
95110
*/
96111
if (!args[1]) {
97112
output += "Nat 64: ";
98113
}
99-
output += "64:ff9b::" + hexify(HEXIP[0]) + hexify(HEXIP[1]) + ":" + hexify(HEXIP[2]) + hexify(HEXIP[3]) + "\n";
100-
114+
output += "64:ff9b::" + hexify(HEXIP[0]) + hexify(HEXIP[1]) + ":" + hexify(HEXIP[2]);
115+
if (range) {
116+
output += "00/120\n";
117+
} else {
118+
output += hexify(HEXIP[3]) + "\n";
119+
}
101120

102121
return output;
103122
}
@@ -165,14 +184,19 @@ class IPv6TransitionAddresses extends Operation {
165184
// Remove blank rows
166185
inputs = inputs.filter(Boolean);
167186
for (let input = 0; input < inputs.length; input++) {
168-
if (/^[0-9]{1,3}(?:\.[0-9]{1,3}){3}$/.test(inputs[input])) {
169-
output += ipTransition(inputs[input]);
170-
} else if (/^([0-9A-F]{2}:){5}[0-9A-F]{2}$/.test(inputs[input].toUpperCase())) {
171-
output += macTransition(input.toLowerCase());
172-
} else if (/^((?:[0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|(?:[0-9a-fA-F]{1,4}:){1,7}:|(?:[0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|(?:[0-9a-fA-F]{1,4}:){1,5}(?::[0-9a-fA-F]{1,4}){1,2}|(?:[0-9a-fA-F]{1,4}:){1,4}(?::[0-9a-fA-F]{1,4}){1,3}|(?:[0-9a-fA-F]{1,4}:){1,3}(?::[0-9a-fA-F]{1,4}){1,4}|(?:[0-9a-fA-F]{1,4}:){1,2}(?::[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:(?:(?::[0-9a-fA-F]{1,4}){1,6})|:(?:(?::[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(?::[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(?:ffff(?::0{1,4}){0,1}:){0,1}(?:(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9])|(?:[0-9a-fA-F]{1,4}:){1,4}:(?:(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/.test(inputs[input])) {
173-
output += unTransition(inputs[input]);
174-
} else {
175-
output = "Enter compressed or expanded IPv6 address, IPv4 address or MAC Address.";
187+
// if ignore ranges is checked and input is a range, skip
188+
if ((args[0] && !inputs[input].includes("\/")) || (!args[0])) {
189+
if (/^[0-9]{1,3}(?:\.[0-9]{1,3}){3}$/.test(inputs[input])) {
190+
output += ipTransition(inputs[input], false);
191+
} else if (/\/24$/.test(inputs[input])) {
192+
output += ipTransition(inputs[input], true);
193+
} else if (/^([0-9A-F]{2}:){5}[0-9A-F]{2}$/.test(inputs[input].toUpperCase())) {
194+
output += macTransition(input.toLowerCase());
195+
} else if (/^((?:[0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|(?:[0-9a-fA-F]{1,4}:){1,7}:|(?:[0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|(?:[0-9a-fA-F]{1,4}:){1,5}(?::[0-9a-fA-F]{1,4}){1,2}|(?:[0-9a-fA-F]{1,4}:){1,4}(?::[0-9a-fA-F]{1,4}){1,3}|(?:[0-9a-fA-F]{1,4}:){1,3}(?::[0-9a-fA-F]{1,4}){1,4}|(?:[0-9a-fA-F]{1,4}:){1,2}(?::[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:(?:(?::[0-9a-fA-F]{1,4}){1,6})|:(?:(?::[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(?::[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(?:ffff(?::0{1,4}){0,1}:){0,1}(?:(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9])|(?:[0-9a-fA-F]{1,4}:){1,4}:(?:(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/.test(inputs[input])) {
196+
output += unTransition(inputs[input]);
197+
} else {
198+
output = "Enter compressed or expanded IPv6 address, IPv4 address or MAC Address.";
199+
}
176200
}
177201
}
178202

0 commit comments

Comments
 (0)