8

I have a functionality in iOS which I need to disable if the user's device network in IPv6. Is there a way we can get the device (iPhone/iPad) IP address as a string programmatically, and then check if it's IPv4 or IPv6 network (or simply tell whether it is on IPv4 or IPv6 network without fetching the actual address)?

The closest I could get to was iPhone/iPad/OSX: How to get my IP address programmatically? (by David H.), which again wants us to specify the network beforehand only, hence doesn't solve my purpose... By his solution either I always get an IPv4 or always an IPv6.

For testing on IPv6 I'm using the Apple's recommended NAT64 tool (https://developer.apple.com/library/ios/documentation/NetworkingInternetWeb/Conceptual/NetworkingOverview/UnderstandingandPreparingfortheIPv6Transition/UnderstandingandPreparingfortheIPv6Transition.html).

As a workaround I'm using the DNS to check (https://hirooka.pro/?p=6169) currently, which I feel is not a proper way as it should be IP address based. Also, quite weirdly, the iPad always shows an IPv4 address (even when connected to IPv6 network) but only varies in the DNS style... Anybody knows why that happens ?

Thanks in advance.

Community
  • 1
  • 1
cirronimbo
  • 909
  • 9
  • 19
  • did you have any luck with determining the network address family programmatically? – Ravi May 13 '16 at 09:54
  • @Ravi Nope... I'm still using the DNS to check. Though it's not a proper way, but you can trust the DNS on this one. I'm using it for quite some time now... Check out the link for the DNS code - (https://hirooka.pro/?p=6169). Let me know if this works :) – cirronimbo May 24 '16 at 09:22
  • seems like that is a reasonable approach for now. thanks for sharing. – Ravi May 24 '16 at 18:01

0 Answers0