I have to go through a range of IPs, the problem is that the format that the function returns is inverted. The format returned by the function is:
First IP
108736
00000000 00000001 10101000 11000000
0 1 168 192
Last IP
-16668480
11111111 00000001 10101000 11000000
255 1 168 192
What I want is that they remain:
192.168.1.0 3232235776
192.168.1.255 3232236031
This to be able to go through them in a cycle.
Edit
The for is this:
for (int i = getNetworkIp(c) + 1, bc = getBroadCastIp(c); i < bc; i++) {
if (isReachable(intToIp(i))) {
ips += "ip " + intToIp(i) + " encontrada\n";
}
}
The problem is that when doing the cycle I have left from: 108736 to -16668480
What you want to do is convert the " endianess ".
This prints
3232235776
Note that normally the conversion tolong
(to see it asunsigned
) is not necessary or desirable at all - if we omit that, the resulting number is-1062731520
Can be used
Integer.reverseBytes
:There is also
Integer.reverseque
reverses all bits of an intReturns the value obtained by reversing the order of the bytes in the two's complement representation of the specified int value.
Returns the value obtained by reversing the order of the bits in the two's complement binary representation of the specified int value.