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: myIP.substring(myIP.indexOf(".")+1, myIP.indexOf(".", myIP.indexOf(".")+1));
etc.
import javax.swing.JOptionPane;
import java.net.InetAddress;
public class WhatIP {
public static void main(String[] args) {
try {
InetAddress ia = InetAddress.getByName(args[0]);
String myIP = ia.toString();
JOptionPane.showMessageDialog( null, myIP+"last Part = "+myIP.substring(myIP.lastIndexOf('.')+q, myIP.length()));
} catch (Exception e) {
e.printStackTrace();
}
}
}