ip address from client

98 views
Skip to first unread message

Gerd Hilgemann

unread,
Oct 4, 2013, 8:34:38 AM10/4/13
to openrtmf...@googlegroups.com
hi,

is it possible to get the read the real external ip-address in lua?

like:
cur_client.ip ???

I study the documentation and can´t find any info about this.

Thx
Gary

Mathieu Poux

unread,
Oct 8, 2013, 1:55:24 AM10/8/13
to openrtmf...@googlegroups.com
client.address,

see wiki :-)
  • address (read-only), address of the client.

Gerd Hilgemann

unread,
Oct 8, 2013, 8:47:08 AM10/8/13
to openrtmf...@googlegroups.com
yes...shame on me! i found the wiki..

dont know if someone can use it , but here is how i try to implement a geoIP check from the opensource maxmind in lua.

so maybe it´s not the best lua, code, let me know if you have some thoughts, i´m critical resident :)

in my lua script i detect and split each clientIP, 

function onConnection(client, userName, meeting)
clientIP = string.split2(client.address,":"); -- call a helper function to split the client ip adress from IP:PORT

after that send the IP to the geo IP module to receive the country:
ipdata = ip_to_country(clientIP[1]);

you can trace the continent like:
print("CLIENT CONTINENT: " .. ipdata.continent);

you also can get city infos, country code,
ipdata = ip_to_city(clientIP[1]);

-- Example geoIP
print(ipdata.country_code);
print(ipdata.country_name);

a simply check to allow only connection from germany
if (ipdate.country_name ~= "Germany") then
client.writer:writeAMFMessage("onPushData","Client is not allowed from his ip-address range to connect!")
error("Client is not allowed to connect");
end

really nice to see how you can extend the server with some scripts.




Mathieu Poux

unread,
Oct 15, 2013, 10:14:34 AM10/15/13
to openrtmf...@googlegroups.com
Interesting :-)

Yes, I love lua binding in Cumulus, and the fact that no restarting is required to modify a server application (dynamic load). One reason among others why I am working on Mona project :-).

Your code seems fine, just check well that no LUA call work in a blocking mode, otherwise you risk to decrease cumulus performance (the reason why I have been forced to rewrite LUASocket, see: https://github.com/OpenRTMFP/Cumulus/wiki/Server-Application,-Sockets)
Reply all
Reply to author
Forward
0 new messages