Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/core/lib/IP.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function ipv4CidrRange(cidr, includeNetworkInfo, enumerateAddresses, allo
ip2 = ip1 | ~mask;

if (includeNetworkInfo) {
output += "Network: " + ipv4ToStr(network) + "\n";
output += "Network: " + ipv4ToStr(ip1) + "\n";
output += "CIDR: " + cidrRange + "\n";
output += "Mask: " + ipv4ToStr(mask) + "\n";
output += "Range: " + ipv4ToStr(ip1) + " - " + ipv4ToStr(ip2) + "\n";
Expand Down Expand Up @@ -88,8 +88,8 @@ export function ipv6CidrRange(cidr, includeNetworkInfo) {
}

if (includeNetworkInfo) {
output += "Network: " + ipv6ToStr(network) + "\n";
output += "Shorthand: " + ipv6ToStr(network, true) + "\n";
output += "Network: " + ipv6ToStr(ip1) + "\n";
output += "Shorthand: " + ipv6ToStr(ip1, true) + "\n";
output += "CIDR: " + cidrRange + "\n";
output += "Mask: " + ipv6ToStr(mask) + "\n";
output += "Range: " + ipv6ToStr(ip1) + " - " + ipv6ToStr(ip2) + "\n";
Expand Down
22 changes: 22 additions & 0 deletions tests/operations/tests/ParseIPRange.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,28 @@ TestRegister.addTests([
},
],
},
{
name: "Parse IPv4 CIDR with host bits set",
input: "10.0.0.1/30",
expectedOutput: "Network: 10.0.0.0\nCIDR: 30\nMask: 255.255.255.252\nRange: 10.0.0.0 - 10.0.0.3\nTotal addresses in range: 4\n\n10.0.0.0\n10.0.0.1\n10.0.0.2\n10.0.0.3",
recipeConfig: [
{
"op": "Parse IP range",
"args": [true, true, false]
},
],
},
{
name: "Parse IPv6 CIDR with host bits set",
input: "2404:6800:4001:0001:0000:0000:0000:0000/48",
expectedOutput: "Network: 2404:6800:4001:0000:0000:0000:0000:0000\nShorthand: 2404:6800:4001::\nCIDR: 48\nMask: ffff:ffff:ffff:0000:0000:0000:0000:0000\nRange: 2404:6800:4001:0000:0000:0000:0000:0000 - 2404:6800:4001:ffff:ffff:ffff:ffff:ffff\nTotal addresses in range: 1.2089258196146292e+24\n\n",
recipeConfig: [
{
"op": "Parse IP range",
"args": [true, true, false]
},
],
},
{
name: "Parse IPv4 hyphenated",
input: "10.0.0.0 - 10.0.0.3",
Expand Down