I need to know, is there any in-built function available that can convert the IP address to an integer value. I can do it by writing own function, but I want to know if is there any in-built function available?
Yes, hashcod will give the hashcode representation of InetAddress object, but this is not what I want. I want the integer reprsentation of the IP address string. For example, suppose IP address is "192.168.1.0", then I want the integer value of this IP address. I can get integer value from this manually by doing [192*(256^3)+168*(256^2)+1*256+0]
Is there any in-built function that can do this for me?
I don't think there is a built-in method to do this for you, so you'd have to implement this yourself.
Ofcourse this will only work for 4-digit IPv4 addresses. Please note that the IPv4 addresses are getting exhausted, and more and more networks will switch to IPv6. Your program will probably not work anymore on a network that requires IPv6 addresses.
I would set an explicit endian to make sure that you don't use big endian instead of little endian.
Or just do it manually:
The << 8 part is equivalent to multiplying by 256, the b & 0xFF turns possible negative values into positive values (e.g. -1 becomes 255), and the | is equivalent to adding (but only because the << 8 ensures the last 8 bits are all 0 and the b & 0xFF part will have only the last 8 bits set).