I am working on developing an application that transforms the initial string:
1.2.3.X
Into multiple strings:
1.2.3.0
1.2.3.1
1.2.3.2
1.2.3.3
1.2.3.4
......
This is a snippet of the code I have written so far:
String.prototype.count=function(c) {
var result = 0, i = 0;
for(i;i<this.length;i++)if(this[i]==c)result++;
return result;
};
var x = ["","","","","","","","","","","","","","","",""]
var brutenumber = ""
var ip = "1.2.X.X"
if (ip.count(".") >= 4) {
console.log("Non valid IP Input");
}
else {
numberX = ip.count("X");
if (numberX < 1) {
console.log("No X given.")
}
else if (numberX > 12) {
console.log("Too many X given! Result can't be an IP")
}
else {
for (i = 1;i <= numberX ; i++ ) {
brutenumber = brutenumber + "9";
}
}
for (d = 0;d <= brutenumber; d++) {
var lastchar = d.toString().slice(-1);
console.log(lastchar)
}
}
My application successfully calculates the number of attempts required to cover all possibilities, but now I am facing a challenge:
for (d = 0 ;d <= brutenumber; d++) {
The issue is that the numbers generated are in the format 0, 1, 10, 11, 12 instead of 001, 002, 003... I need to adjust the code to achieve this. Additionally, I am struggling with inserting values for the X in the search string like 1.2.3.X. I am open to any suggestions or solutions for this task, as the searchString can vary in format. Thank you for your help!
Thanks