Skip to content

Commit a61feb0

Browse files
committed
Operation Change IP Format: added Little Endian format
1 parent 8509af2 commit a61feb0

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed

src/core/operations/ChangeIPFormat.mjs

+16-2
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ class ChangeIPFormat extends Operation {
2929
{
3030
"name": "Input format",
3131
"type": "option",
32-
"value": ["Dotted Decimal", "Decimal", "Octal", "Hex"]
32+
"value": ["Dotted Decimal", "Decimal", "Decimal (Little Endian)", "Octal", "Octal (Little Endian)", "Hex"]
3333
},
3434
{
3535
"name": "Output format",
3636
"type": "option",
37-
"value": ["Dotted Decimal", "Decimal", "Octal", "Hex"]
37+
"value": ["Dotted Decimal", "Decimal", "Decimal (Little Endian)", "Octal", "Octal (Little Endian)", "Hex"]
3838
}
3939
];
4040
}
@@ -71,9 +71,15 @@ class ChangeIPFormat extends Operation {
7171
case "Decimal":
7272
baIp = this.fromNumber(lines[i].toString(), 10);
7373
break;
74+
case "Decimal (Little Endian)":
75+
baIp = Utils.intToByteArray(parseInt(lines[i].toString(), 10), 4, "little");
76+
break;
7477
case "Octal":
7578
baIp = this.fromNumber(lines[i].toString(), 8);
7679
break;
80+
case "Octal (Little Endian)":
81+
baIp = Utils.intToByteArray(parseInt(lines[i].toString(), 8), 4, "little");
82+
break;
7783
case "Hex":
7884
baIp = fromHex(lines[i]);
7985
break;
@@ -98,10 +104,18 @@ class ChangeIPFormat extends Operation {
98104
decIp = ((baIp[0] << 24) | (baIp[1] << 16) | (baIp[2] << 8) | baIp[3]) >>> 0;
99105
output += decIp.toString() + "\n";
100106
break;
107+
case "Decimal (Little Endian)":
108+
decIp = Utils.byteArrayToInt(baIp, "little");
109+
output += decIp.toString() + "\n";
110+
break;
101111
case "Octal":
102112
decIp = ((baIp[0] << 24) | (baIp[1] << 16) | (baIp[2] << 8) | baIp[3]) >>> 0;
103113
output += "0" + decIp.toString(8) + "\n";
104114
break;
115+
case "Octal (Little Endian)":
116+
decIp = Utils.byteArrayToInt(baIp, "little");
117+
output += "0" + decIp.toString(8) + "\n";
118+
break;
105119
case "Hex":
106120
hexIp = "";
107121
for (j = 0; j < baIp.length; j++) {

tests/operations/tests/ChangeIPFormat.mjs

+40
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,45 @@ TestRegister.addTests([
4848
args: ["Octal", "Decimal"],
4949
},
5050
],
51+
}, {
52+
name: "Change IP format: Decimal (Little Endian) to Dotted Decimal",
53+
input: "16885952",
54+
expectedOutput: "192.168.1.1",
55+
recipeConfig: [
56+
{
57+
op: "Change IP format",
58+
args: ["Decimal (Little Endian)", "Dotted Decimal"],
59+
},
60+
],
61+
}, {
62+
name: "Change IP format: Dotted Decimal to Decimal (Little Endian)",
63+
input: "192.168.1.1",
64+
expectedOutput: "16885952",
65+
recipeConfig: [
66+
{
67+
op: "Change IP format",
68+
args: ["Dotted Decimal", "Decimal (Little Endian)"],
69+
},
70+
],
71+
}, {
72+
name: "Change IP format: Octal (Little Endian) to Dotted Decimal",
73+
input: "0100324300",
74+
expectedOutput: "192.168.1.1",
75+
recipeConfig: [
76+
{
77+
op: "Change IP format",
78+
args: ["Octal (Little Endian)", "Dotted Decimal"],
79+
},
80+
],
81+
}, {
82+
name: "Change IP format: Dotted Decimal to Octal (Little Endian)",
83+
input: "192.168.1.1",
84+
expectedOutput: "0100324300",
85+
recipeConfig: [
86+
{
87+
op: "Change IP format",
88+
args: ["Dotted Decimal", "Octal (Little Endian)"],
89+
},
90+
],
5191
},
5292
]);

0 commit comments

Comments
 (0)