External ip address in Android programmatically

前提是你 提交于 2019-12-05 00:05:19

问题


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.


回答1:


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".




回答2:


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



来源:https://stackoverflow.com/questions/6932427/external-ip-address-in-android-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!