1

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?

Community
  • 1
  • 1
Anton Unt
  • 1,835
  • 1
  • 21
  • 47
  • You'll probably need to query an online IP service. – Linuxios Nov 05 '13 at 15:01
  • 1
    Possible duplicate of [how to get the external ip in objective c](http://stackoverflow.com/questions/5450621/how-to-get-the-external-ip-in-objective-c) – Larme Oct 26 '15 at 09:23

1 Answers1

1

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.

Nikos M.
  • 13,685
  • 4
  • 47
  • 61
  • If you copy an answer, at least credit the [original](http://stackoverflow.com/a/5450813) ;) – vhu Oct 26 '15 at 11:14