Unfortunately, you won't be able to do this because VBScript and JScript can't handle the numerical precision required.
Here was my first attempt in VBScript
<%
Option Explicit
Const base = 65536
Dim ipv6: ipv6 = "2a00:85c0:0001:0000:0000:0000:0241:0023"
Dim pwr: pwr = 8
Dim hextets: hextets = Split(ipv6, ":")
Dim hextet, ipnum
If IsArray(hextets) Then
For Each hextet In hextets
pwr = pwr - 1
ipnum = ipnum + ((base^pwr) * CLng("&h" & hextet))
Next
End If
%>
<!doctype html>
<html>
<head>
<title>IPv6 to IP Number</title>
</head>
<body>
<pre><%= ipv6 %></pre>
<pre><%= FormatNumber(ipnum, 0, -2, -2, false) %></pre>
</body>
</html>
Output:
2a00:85c0:0001:0000:0000:0000:0241:0023
55830288595252200000000000000000000000
The problem here is the calculation is right but the number can't handle the precision so when it reaches the maximum it defaults to 0
.
My next attempt was JScript (not my strongest language)
<% @Language = "JScript" %>
<%
var base = 65536;
var ipv6 = "2a00:85c0:0001:0000:0000:0000:0241:0023";
var pwr = 8;
var hextets = ipv6.split(":");
var ipnum;
for (var hextet in hextets) {
pwr--;
ipnum += (Math.pow(base, pwr) * parseInt("0x" + hextets[hextet]));
};
%>
<!doctype html>
<html>
<head>
<title>IPv6 to IP Number</title>
</head>
<body>
<pre><%= ipv6 %></pre>
<pre><%= ipnum %></pre>
</body>
</html>
Output:
2a00:85c0:0001:0000:0000:0000:0241:0023
-1.#IND
This time it fails with a -1.#IND
conversion error which basically means the number is too big to be represented.
So while not doable directly in VBScript or JScript you could still build a COM exposed class in another language (C#, VB.Net etc) that did the computation and produced a string that VBScript / Jscript could display.
Useful Links
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…