I’d like to get the IP address of my iOS device. How can you do that since the Networking Object is not available in Mobile apps.
I’m asking because sockets in iOS seem to have a different local IP address than what the phone actually has. For example, my IP address on my device is 192.168.0.164 but my device is showing a local address on sockets of 100.122.67.209.
iOS must use some intermediate addressing. So how do I find my actual IP?
Nope. Socket.LocalAddress gives the 100.122.67.209 address which is not what I need.
Basically I am sending some data over UDP and don’t want to act in my UDP socket on data that I have sent. But as the datagram has the real address of the phone vs. the “local” address of the socket, the socket sees it as data coming from another source.
I suppose I could send a message over UDP with my local address in it. Then when I receive it, I can see the sender address of the datagram. Then I can store that as my actual IP address. That would work but I was looking for a more formal way to do this…
Nope. I’m wondering if it has something to do with the Private WiFi address in iOS. But even after turning that off, the same address still shows up that is not the address of the phone.
So what I am doing is sending a UDP packet that is my devices unique ID. When I receive that back, I check to make sure that it’s the same as my device. If so then I store the datagram’s address as the IP address of the device. Once I have the IP address stored, I don’t do this check again. Seems to work.
Understood, Greg. So I turned it off. Even after turning off the Private WiFi Address and turning off Limit IP Address tracking in my connection, it still showed that same 100.122.67.209 address.
I don’t know if iOS needs to then disconnect from the WiFi and reconnect in order to lose that or what.
But it is still a valid question when developing apps for iOS - is there a way to get the actual IP address of the device? The way I am doing works, but it’s also somewhat of a hack.
Even if turning off all that iOS network obscurity stuff works, I can’t expect users to do that…
You must restart the device for those changes to take affect. It actually randomizes the MAC address of the device. Until you restart it, it continues to supply the randomized MAC address rather than the physical MAC address of the device. Once it’s supplying the actual physical MAC address then your router will assign it a different address.
OK. I was wondering about that. Apple certainly isn’t clear about it when turning off the privacy features.
Well, it would be nice if Xojo offered a way of getting the actual address of the device on the local network. Like I said, sending a UDP package with my UID works as I receive the packet and can get the IP address from the datagram. But that seems like more of a hack than a real way to do things…
Otherwise, every UDP packet I send gets heard by my app and acted on by my app (which it shouldn’t do if it is sending the packet!). UDPSocket.SendToSelf = False doesn’t do much in this case…
The Apple private WiFi feature broke many schools networks because they used MAC address filtering to control access to their networks. Had to switch to other methods because they couldn’t make everyone turn off that feature.
I did a little research about how you would get the IP addresses in objective C as a precursor to creating the declares. The short answer is that Apple doesn’t provide a way to do this except with some very low-level network commands.
I’d bet that Christian could add this to MBS, but I don’t know if Apple will even accept apps that do this.