.
is a special character in regular expressions, which is what is used to split a string.
To get around this, you need to escape the .
. That leads us to \.
Unfortunately, \
is ALSO a special character in the java string, so that must also be escaped, to make \\.
Our "final" result is ip.split("\\.");
In a related issue, the whole process can be averted entirely. There's no sense in doing something that a standard library already has done for us.
Consider the following
byte[] ipOctets = InetAddress.getByName(ip).getAddress();
The only issue here is to remember that if you want the int value, you have to extract it with &
like int octet = ipOctets[0] & 0xFF;