ColdFusion IPv6 for 128-bit unsigned int

I needed to create a function that could convert an IPv6 address to its numeric representation.

Working with IPv4 is pretty straight forward, as it uses a 32-bit unsigned int to represent it numerically. IPv6 is represented by a 128-bit unsigned int. This number size is too large for ColdFusion's built-in logic functions.

This function should use the underlying Java system for conversion.

Need a function for the opposite: ColdFusion 128-bit unsigned int for IPv6

-2
source share
1 answer

This is a function that I wrote to convert an IPv6 address to a 128-bit unsigned int.

<cffunction name="IPv6ToUInt128" returntype="numeric" output="no" access="public" hint="returns uint128 number for IPv6 address">
    <cfargument name="vcIPv6" type="string" required="yes" hint="IPv6 address">

    <cfif arguments.vcIPv6 EQ "">
        <cfreturn 0>
    </cfif>

    <cfset local['javaMathBigInteger'] = CreateObject("java", "java.math.BigInteger")>
    <cfset local['javaNetInetAddress'] = CreateObject("java", "java.net.InetAddress")>
    <cftry>
        <cfset local['uint128'] = local.javaMathBigInteger.init(1, local.javaNetInetAddress.getByName(arguments.vcIPv6).getAddress()).toString()>
        <cfreturn local.uint128>
        <cfcatch type="any">
            <cfreturn 0>
        </cfcatch>
    </cftry>
</cffunction>

, .

0

Source: https://habr.com/ru/post/1673857/


All Articles