It's not an octet. It's decimal. This example here shows the last part of an IP. You can modify it to get the 1st, 2nd or 3rd part.
1st: myIP.substring(0, myIP.indexOf(".");
2nd:...