How to get the external ip in Objective-C

前端 未结 3 1402
萌比男神i
萌比男神i 2020-12-06 07:41

I looked for some code that will help me to get the ip that the iPhone connect with.

I find this one:

- (NSString *)getIPAddress
{
    NSString *addr         


        
相关标签:
3条回答
  • 2020-12-06 08:22

    Check Apple's PortMapper, does exactly what you want.

    As of iOS7 this is irrelevant.

    0 讨论(0)
  • 2020-12-06 08:24

    Have a look at the example in my second Answer here.

    In a nutshell it uses *http://www.dyndns.org/cgi-bin/check_ip.cg*i to get the extenal I.P

    0 讨论(0)
  • 2020-12-06 08:29

    The easiest way to get your internet ip address from code is to use NSURLConnection.

    For the URL you can use: http://www.whatismyip.com/m/mobile.asp or http://checkip.dyndns.com/

    Just parse the return data and you have your external ip address.

    0 讨论(0)
提交回复
热议问题