Can we access device IP address in iOS 12? is it allowed by apple to access device IP address without using any private API?

I want to track iOS device's Ip address and submit it to server for fraud detection purpose.

so

#1. In iOS 12 using swift language, can we access device ip address without any restriction?

#2. Whether apple allowed to track device ip address and is there any public API provided by apple to track device ip address?

#3. if we track device IP address wther apple reject app on appstore?

Replies

I want to track iOS device's Ip address and submit it to server for fraud detection purpose.

This seems like a bad idea. iOS devices have multiple network interfaces and, in most cases, these network interfaces have multiple addresses which can change frequently (for IPv6) and can be shared between users (IPv4 with NAT). For example:

  • My iOS device at home has two working interfaces:

    • Wi-Fi — This has both an IPv4 and an IPv6 address. The IPv4 address is shared by all the other members of my household. The IPv6 address regularly changes as a privacy measure (see RFC 4941).

    • WWAN — See below.

  • My iOS device on the road just has WWAN. My cellular provider currently hands out NATed IPv4 addresses, where one address is shared between different devices from different customers. Other cellular providers use DNS64/NAT64, and thus the device has no IPv4 address at all.

  • It’s common for organisations to also use NAT on their internal networks, meaning that a single public IPv4 address could potentially be used by anyone in that organisation.

  • It’s also common to see multiple levels of NAT. For example, if you have a WWAN-to-Wi-Fi gateway, there’s two levels of NAT (one on the gateway, one implemented by the cellular provider).

Trying to turn all of the above into a useful metric for fraud prevention is going to be challenging.

Regardless…

1. In iOS 12 using swift language, can we access device ip address without any restriction?

Yes.

2. Whether apple allowed to track device ip address

This seems like a duplicate of question 3.

is there any public API provided by apple to track device ip address?

There are APIs to get IP address information (for example,

getifaddrs
) but that’s not the same as tracking it (I’m not even sure what you mean by “tracking” at the API level).

Keep in mind that local APIs only know about local IP addresses. If you want to discover the public IP address, you’ll need to implement that yourself, being cognisant that there may be multiple levels of NAT.

3. if we track device IP address wther apple reject app on appstore?

I don’t work for App Review and thus can’t answer questions about their policies.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Thanks Eskimo for prompt response. I appreciate for your help.


#1. OK


I have few more queries with reference to #2


There are APIs to get IP address information (for example,

getifaddrs
) but that’s not the same as tracking it (I’m not even sure what you mean by “tracking” at the API level) .-> tracking in the sense I want get device Ip address Programatically in IOS application.


I want to make sure, if I use "

getifaddrs" API, I will get device IP Address(I want to make sure getting IP address in application is not restricted by Apple right? like getting device UDID is restricted by Apple, make me correct if I am wrong)


#3. OK(from above queries)


#4 In device setting we have IP address Under(Settings- Wifi- DHCP). Is it private IP address or Public IP address over WIFi Network? do we have any provision to access it in app - by swift programatically?


#5 If I want to get device Public IP address in ios application, how it works in case of Cellular Data? is it by deafault public IP address or goes through NAT(like cellular ISP provider)?

1. I want to make sure, if I use

getifaddrs
API, I will get device IP Address

Yes.

I want to make sure getting IP address in application is not restricted by Apple right?

I don’t work for App Review and thus can’t give you definitive answers about their policies. However, my experience is that there are no App Review restrictions on using IP addresses, other than their general guidelines about privacy and personal data.

4. In device setting we have IP address Under (Settings > Wi-Fi >DHCP). Is it private IP address or Public IP address over WIFi Network?

Settings > Wi-Fi displays local addresses. This is exactly the sort of info you’ll get back from

getifaddrs
.

5. If I want to get device Public IP address in ios application, how it works in case of Cellular Data?

Apple does not have an API for getting the public IP address for an interface [1]. There are various industry standard ways to discover the public IP address when you’re behind a NAT. This is not Apple-specific technology, so it’s not something I can help you with. You’ll have to research it independently.

Be aware that:

  • You can’t be sure that you are behind a NAT, even on WWAN. There are some WWAN providers that return non-NATed IP addresses. In most cases these are IPv6 addresses, using DNS64/NAT64, but I have encountered WWAN providers that hand out non-NATed IPv4 addresses!

  • Any given interface may be behind multiple levels of NAT, and I’m using the term public IP address to refer to the outermost of those. This is probably what matters in your case, but folks doing NAT traversal may need to discover and handle each level of NAT explicitly.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

[1] That’s not quite true. In

<dns_sd.h>
you’ll find
DNSServiceNATPortMappingCreate
, which may yield useful results in some circumstances. However, it does not work in all circumstances — for example, it generally fails on WWAN — and thus won’t meet your needs.

Thanks Eskimo, Its helpful to me.

[1] That’s not quite true. In <dns_sd.h> you’ll find DNSServiceNATPortMappingCreate, which may yield useful results in some circumstances. However, it does not work in all circumstances — for example, it generally fails on WWAN — and thus won’t meet your needs.

do you mean that DNSServiceNATPortMappingCreate does not return an external IP address on WWAN or that it does not work at all on WWAN (so it is not possible (or reliable) to use PCP / NAT-PMP functionality for a WWAN interface)?

DNSServiceNATPortMappingCreate requires support from the network (PCP, NAT-PMP or UPnP) and my experience is that cellular providers don’t offer that support.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

In addition to IP address can we get DHCP options? Im wondering with an App can I get the value that was sent in DHCP Option 114 (which would be a string) I know iOS is querying it as i can see it in my custom DHCP server logs… How to read the value it in swift?

On macOS you can get the final DHCP options using SCDynamicStoreCopyDHCPInfo. That’s not available on iOS and, honestly, I can’t imagine us ever providing that very generic API given iOS’s privacy constraints. If you need this specific option, I recommend that you file an enhancement request for an API to get it. Be specific about the reason you need this. For example, if you’re working on a hotspot helper mention that because, from a privacy perspective, it’d be easier to justify adding this behind the existing hotspot helper protections.

Please post your bug number, just for the record.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"