Thank you for posting the data.
The results you got when connected to the wifi are exactly what I would expect. It appears that the lua socket method is working correctly. 192.168.1.xxx is a local address. It was assigned to your iPad2 and iPhone4 by the wireless router that they were connected to.
When you turn wifi off you would no longer have a valid IP address. When you request a IP address from your device(when your device does not have one) you should get some default value like 127.0.0.1 or 0.0.0.0.
I find it odd that the lua socket method returned 1x.8x.22x.9x. Could it be that you had your data connection on and it was using this connection? Even if that was the case your method returned 7x.1x.7x.12x.
So in the case when the wifi was turned off you used both my method and yours and got different results?
Does the iPhone have a way to turn data off? I would be interested in seeing the results of that.
To clarify:
When you have a wireless device and you connect to some wireless router, that router assigns your device an ip address. (192.168.1.xxx). It has a table where it keeps track of all of the devices connected to it by storing their ip and mac addresses.
The router functions in a similar way. When it first turns on it gets its IP address from your internet service provider(ISP). That is the 7x.1x.7x.12x address you mentioned. The ISP has a large table of all these addresses and the customers who are currently assigned them.
When your device communicates over the internet it has to go through your router. Your router does not use your local address it assigned your device in this instance. Instead, it uses its own IP address when it sends out communication. That is why when you connect to an external server like whatismyip.org you get the routers address and not your devices.
"So if I understand your interpretation, your version is returning my router’s IP address."
Nope, it is your actual device’s (ipad, iphone) IP address.
"When I’m going through my phone’s data plan over a cellular network am I then getting some cell tower’s IP?"
I am not sure about this but I think that is the general idea.
"What I don’t understand is what IP is being returned with the other method using an external server. I would have thought it would also be that same IP from my router as returned by your method, but it’s not"
What you get from the other method(whatismyip.org) is your routers IP address
What you get when you use my method (lua socket script) is your devices IP address
I can think of one instance where they could be the same. That is if your computer were connected directly to your internet connection without a router in between and you were using the simulator.
I hope that clears it up for you. The networking lingo can be pretty confusing. I am by no means an expert, I have a general understanding of how it works.
[import]uid: 106158 topic_id: 25484 reply_id: 103301[/import]