VBScript ip2long function

A VBScript equivalent of PHP’s ip2long


Function ip2long( ip_address )

    ip2long = false

    If preg_match("/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/",ip_address,",",") Then
        Dim parts
        parts = Split(ip_address,".")
        ip2long = parts(0) * pow(256,3) + _
                  parts(1) * pow(256,2) + _
                  parts(2) * pow(256,1) + _
                  parts(3) * pow(256,0)
    End If

End Function

Please also note that php.vbs offers community built functions and goes by the McDonald’s Theory. We’ll put online functions that are far from perfect, in the hopes to spark better contributions. Do you have one? Then please just:

Other PHP functions in the network extension