Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine device public ip

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

like image 254
source.rar Avatar asked Jun 10 '11 14:06

source.rar


People also ask

Can you identify a device by IP address?

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.

Can you trace a public IP address?

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.

Which devices have a public IP address?

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.


2 Answers

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.

like image 111
Brad Christie Avatar answered Oct 06 '22 16:10

Brad Christie


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();
}
like image 40
Eng.Fouad Avatar answered Oct 06 '22 15:10

Eng.Fouad