Does anyone know how I could get the public ip address of an android device?
I am trying to run a server socket (just experimenting with simple p2p).
This requires informing the local and remote users of each others public ip. I did find this thread How to get IP address of the device from code? which contains a link to an article (http://www.droidnova.com/get-the-ip-address-of-your-device,304.html) that shows how to get the IP. However this returns the local ip when connected through a router and I would like to get the actual public IP instead.
TIA
Can an IP address identify me? No, an ip address does not reveal personal information (like a name, social security number or physical address). Millions of devices, like modems and routers keep logs of ip addresses. Your modem at home, or the 4G antennae you connect to with your phone are logging your ip addresses.
While the IP address used to route Internet traffic to your computer it does not reveal your location. If someone was able to get your IP address they could learn a bit about your Internet service, such as which provider you use to connect to the Internet, but they really can't locate you, your home, or your office.
A public IP address is an IP address that your home or business router receives from your ISP; it's used when you access the internet. Public IP addresses are required for any publicly accessible network hardware such as a home router and the servers that host websites.
Just visit http://automation.whatismyip.com/n09230945.asp and scrape it?
whatismyip.com is perfect for getting the IP, though the site requests you only hit it about once every 5 minutes.
UPDATE FEB 2015
WhatIsMyIp now exposes a developer API that you can use.
Parse the public IP address from checkip.org (Using JSoup):
public static String getPublicIP() throws IOException
{
Document doc = Jsoup.connect("http://www.checkip.org").get();
return doc.getElementById("yourip").select("h1").first().select("span").text();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With