[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Retrieve public IP
- From: Philipp Janda <siffiejoe@...>
- Date: Mon, 25 May 2015 10:00:46 +0200
Hi!
Am 25.05.2015 um 08:18 schröbte Claudio Mussoni:
Hello to everyone,I need to get the public address from my router with LUA.
This is a PHP example: $my_public_ip = $_SERVER['REMOTE_ADDR'];
I searched around but I' ve not found examples.Someone can help me out?Thank's a lot.ByeClaudio
If you have a connected TCP socket (like PHP probably does), that's easy:
local address, port = s:getsockname() -- LuaSocket[1] or NixIO[2]
If you don't have a connected socket you can query interface information
using NixIO's `getifaddrs()`[3] function. If you are on an OpenWRT
Router you probably have NixIO installed already, but LUnix[4] also has
a binding to that function. You may get multiple results though, and
you'll have to decide which one is the real external interface.
Or you query an external server like Thijs suggested (which will also
work if you have some form of masquerading/NAT between your router and
the internet).
Philipp
[1]: http://w3.impa.br/~diego/software/luasocket/tcp.html#getsockname
[2]:
http://luci.subsignal.org/api/nixio/modules/nixio.Socket.html#Socket.getsockname
[3]:
http://luci.subsignal.org/api/nixio/modules/nixio.html#nixio.getifaddrs
[4]: http://www.25thandclement.com/~william/projects/lunix.html