External ip address in Android programmatically
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 w开发者_高级运维ebsites, is there a built in way to get this?
Also, I want the external ipaddress if the user is connected to wifi.
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".
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
精彩评论