So I need to retrieve the user's WAN IP from within the app I am building. I saw this answer here: iPhone/iPad/OSX: How to get my IP address programmatically?
But this only returns the user's IP address in the local network.
By what means can I know the user's WAN IP from within the app?
The easiest way to get your wap ip address is to use NSURLConnection
.
For the URL you can use: http://www.whatismyip.com/m/mobile.asp or http://www.dyndns.org/cgi-bin/check_ip.cgi
Just parse the return data and you have your external ip address. A complete implementation is shown here . It is not the most efficient way, but it works.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.