the thing is there is no such thing like my ip. Your machine can have multiple interfaces and each interface can have multiple IPs. so i dnt really think you want to get into it. All you can do is to try web APIs to get your external IP address. Here is a code in java which is actually just looking for your ip on internet with the help of these sites
public static String getIpAddress()
{
URL myIP;
try {
myIP = new URL("http://api.externalip.net/ip/");
BufferedReader in = new BufferedReader(
new InputStreamReader(myIP.openStream())
);
return in.readLine();
} catch (Exception e)
{
try
{
myIP = new URL("http://myip.dnsomatic.com/");
BufferedReader in = new BufferedReader(
new InputStreamReader(myIP.openStream())
);
return in.readLine();
} catch (Exception e1)
{
try {
myIP = new URL("http://icanhazip.com/");
BufferedReader in = new BufferedReader(
new InputStreamReader(myIP.openStream())
);
return in.readLine();
} catch (Exception e2) {
e2.printStackTrace();
}
}
}
return null;
}
now with this you can get your ip from the internet but again that is your external IP