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

Did you find away to get the devices ip address?

Matt

Were you able to figure out a solution to this?

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
--
--  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 
views:715 update:2011/9/28 8:56:32
corona forums © 2003-2011