i got this code to convert ip address to a long range
i have adjusted to b4a as following
but the result in B4A is different from the php code
in php i got a result of
in b4a/b4j i got
using that ip address 165.174.23.96
B4X:
function Dot2LongIP ($IPaddr) {
if ($IPaddr == "")
{
return 0;
} else {
$ips = explode(".", $IPaddr);
return ($ips[3] + $ips[2] * 256 + $ips[1] * 256 * 256 + $ips[0] * 256 * 256 * 256);
}
}
i have adjusted to b4a as following
B4X:
Sub dot2longip(ipaddr As String) As String
Dim iptowork As String
Dim iparray() As String
Dim ip1 As Int
Dim ip2 As Int
Dim ip3 As Int
Dim ip4 As Int
Dim iplongword As Long
Dim dotstoip As String
Dim iplength As Int
iptowork = ipaddr
iparray = Regex.Split("\.", iptowork)
iplength = iparray.Length
Log(iplength)
If iplength = 4 Then
ip1 = iparray(3)
ip2 = iparray(2)
ip3 = iparray(1)
ip4 = iparray(0)
iplongword = ip1 + ip2 * 256 + ip3 * 256 * 256 + ip4 * 256 * 256 * 256
dotstoip = iplongword
End If
Return dotstoip
End Sub
but the result in B4A is different from the php code
in php i got a result of
2779649888
in b4a/b4j i got
-1515317408
using that ip address 165.174.23.96