Get IP address of device

Hi,

I am using the LuaSocket libraries in my application and everything is fine for connecting to servers (as a client) but I need to find out the IP address of the iPhone/iPod Touch/iPad…

On the simulator I can use:

socket.dns.toip(socket.dns.gethostname())

But that isn’t working on the device…

Can anyone help with this… Is there a better method???

Thanks, Gary [import]uid: 4415 topic_id: 610 reply_id: 300610[/import]

Did you find away to get the devices ip address?

Matt [import]uid: 5354 topic_id: 610 reply_id: 10349[/import]

Were you able to figure out a solution to this? [import]uid: 41124 topic_id: 610 reply_id: 29480[/import]

I found a way to find the device’s local IP using LuaSocket. I’ve only tried it on a wifi network so far and it returns the LAN IP. If you want the WAN IP you’re gonna have to connect to something like http://whatismyip.org/ and parse the html for it.
It will probably work on cellular but I haven’t tested it.
Anyway, start by importing sockets local socket = require( "socket" ) Then, when you want an IP, call [lua]–
– A hacky way to find local
– IP of device

function findDeviceIP()

local client = socket.connect( “www.google.com”, 80 )

local ip, port = client:getsockname()

print(ip)

client:close()

return ip

end [/lua]
If anyone tries this let me know how it works out for you. [import]uid: 55576 topic_id: 610 reply_id: 47786[/import]

As Duff333 suggested, I tried getting the public IP of the device by using http://whatismyip.org/ and… it worked! Here’s my code:

[lua]-- A hacky way to find local IP of device
local deviceIP

local function whatismyipListener(event)
if ( event.isError ) then
print(“Network error!”)
else
deviceIP = event.response
print("IP response: "…deviceIP)
end
end

network.request( “http://whatismyip.org/”, “GET”, whatismyipListener )[/lua] [import]uid: 9422 topic_id: 610 reply_id: 60334[/import]