5

I have searched everywhere on how to get the external ip address with no avail. I am able to successfully get the local ip address.

In short what i want to do to get the same ip address as when I go on whatip.com or whatismyipaddress.com. However, I do not want to make any calls to the websites, is there a built in way to get this?

Also, I want the external ipaddress if the user is connected to wifi.

Cœur
  • 37,241
  • 25
  • 195
  • 267
thunderousNinja
  • 3,510
  • 9
  • 37
  • 49
  • [one of such services](http://ifconfig.me/ip.json) - returns single plain string – Alexander Malakhov Apr 09 '14 at 11:07
  • Possible duplicate of [How to get IP address of the device from code?](https://stackoverflow.com/questions/6064510/how-to-get-ip-address-of-the-device-from-code) – mike47 Jul 11 '17 at 21:46

2 Answers2

13

However, I do not want to make any calls to the websites, is there a built in way to get this?

No. This is impossible on most pieces of hardware, including desktops and notebooks, let alone phones. Generally, you are behind some sort of NAT, which defines your "external ip address".

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Ugh thats a bummer... Does it make a difference if the phone is connected over the wifi network instead? – thunderousNinja Aug 03 '11 at 20:00
  • 2
    @unknown: No. Again, generally, you are behind some sort of NAT, which defines your "external ip address". This is why services like `whatismyipaddress.com` exist. If everybody knew their external IP address, we wouldn't need such services. – CommonsWare Aug 03 '11 at 20:02
3

IcanHazIP.com gives you a short and sweet response for the external IP.

However, using that URL on a large number of phones will inevitably yield the same IP for a few devices (for the reason that CommonsWare has already explained).

Idea: The data might be more meaningful if you collect the external IP combined with the local IP. So send a request to IcanHazIP.com followed by the following sample code for the Local IP: http://chandan-tech.blogspot.com/2010/12/finding-ip-address-of-your-android.html

By the way, I've worked on development devices with Modems that were activated by Sprint and their local IP's actually were external IP's

Someone Somewhere
  • 23,475
  • 11
  • 118
  • 166