For geolocation purposes, I am trying to get a string representation of the numeric value of an ip v6 address. Because Classic ASP doesn't handle bigint values, I'm attempting to work around it with a Javascript function.
Based on this working Fiddle: https://jsfiddle.net/adamish/mrx3880p/ that uses the biginteger.js library, I adapted the library to work as a valid include for ASP.
var ip = '2a00:85c0:0001:0000:0000:0000:0241:0023';
// simulate your address.binaryZeroPad(); method
var parts = [];
ip.split(":").forEach(function(it) {
var bin = parseInt(it, 16).toString(2);
while (bin.length < 16) {
bin = "0" + bin;
}
parts.push(bin);
})
var bin = parts.join("");
// Use BigInteger library
var dec = bigInt(bin, 2).toString();
console.log(dec);
The code in the Fiddle converts the ipv6 into its binary representation then calls the toString function, requesting the conversion in base 2.
It works in the Fiddle. However, I can't get it to work in my code as the return value is in scientific notation, which is not good for me.
The goal is to input the string "2a00:85c0:1::241:23" (or its non shortened version, "2a00:85c0:0001:0000:0000:0000:0241:0023", doesn't matter) and output a string representation of the numeric equivalent, or "55830288595252163998698714105846497315".
As I am limited to what I can use in Classic ASP, has anyone any pointer on how I can get that conversion to work?