I deleted my previous answer as it wasn't very helpful. Its been established that you can't use Classic ASP to convert an IPv6 address to a numeric value using VBscript. JScript could be possible, but seems unlikley.
I also convert and log IPv4/6 numeric values for geolocation purposes on a high traffic Classic ASP website.
For IPv4, the conversion is quite simple using VBscript:
Function IPv4ToNumber(ByVal IPv4)
Dim i, Pos, PrevPos, Num
For i = 1 To 4
Pos = InStr(PrevPos + 1, IPv4, ".", 1)
If i = 4 Then pos = Len(IPv4) + 1
Num = Int(Mid(IPv4, PrevPos + 1, Pos - PrevPos - 1))
PrevPos = Pos
IPv4ToNumber = ((Num Mod 256) * (256 ^ (4 - i))) + IPv4ToNumber
Next
End function
Here's another useful VBscript function that returns the type of IP (IPv4, IPv6 or an empty string for invalid IPs). You could just use InStr()
:
.
= IPv4
:
= IPv6
But this function uses regular expressions to properly validate IP addresses:
Function IP_Type(ByVal IP)
IP_Type = "" ' Default
' Check for valid IPv4 and IPv6 addresses
Dim IP_RegExp
If Len(IP) >= 7 AND Len(IP) <= 15 Then
' Potential IPv4
Set IP_RegExp = New RegExp
IP_RegExp.Pattern = "^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$"
IP_Type = IP_RegExp.Test(IP)
If IP_Type Then IP_Type = "IPv4" Else IP_Type = ""
Set IP_RegExp = Nothing
ElseIf Len(IP) > 15 AND Len(IP) <= 39 Then
' Potential IPv6
Set IP_RegExp = New RegExp
IP_RegExp.Pattern = "^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$"
IP_Type = IP_RegExp.Test(IP)
If IP_Type Then IP_Type = "IPv6" Else IP_Type = ""
Set IP_RegExp = Nothing
End If
End Function
For IPv6, I use MySQL to calculate the numeric value. Here's a simple SELECT example:
SELECT CAST(
CONV(
SUBSTR(
HEX(
INET6_ATON('2a00:85c0:0001:0000:0000:0000:0241:0023')
)
,1,16)
,16,10
)AS DECIMAL(65))
*18446744073709551616
+CAST(
CONV(
SUBSTR(
HEX(
INET6_ATON('2a00:85c0:0001:0000:0000:0000:0241:0023')
)
,17,16)
,16,10
) AS DECIMAL(65)) AS ipv6_num;
Output: 55830288595252163998698714105846497315
(using either the full or shortened IPv6 address)
It also works with MariaDB. For other SQL platforms, the logic is the same, but the syntax and functions will probably need to be replaced with equivalents.
If you're logging IP numeric values for geolocation purposes, you're obviously using a database, so adapting the above MySQL code for other SQL platforms is the best solution I can offer.
I also looked up an IP to numeric API (free or subscription based) but there doesn't seem to be any (IPv6 is still quite rare, so a REST API call could be a possible solution). Hopefully there is a solution using JScript, or as already mentioned you could use a COM DLL (I have experience with this, I've created a number of COM DLL's using C# for use in Classic ASP applications on my GitHub page. You will need root access though. I'm using a new laptop so will need to reinstall Visual Studio, but I'll create a COM DLL for IP to numeric values when I get the time).