ewindsor
ewindsor

Reputation: 885

ejabberd ip address

Does anyone know if there's a direct way to map an IP address to a user logged into ejabberd? I found an indirect way by modifying ejabberd_receiver.erl and calling inet:peername(Socket) from here: Determining IP address and port of an incoming TCP/IP connection in Erlang

but there doesn't seem to be a way to link a socket to a user after they've successfully been authenticated. If anyone knows of a way, please let me know! Thanks.

Upvotes: 1

Views: 1423

Answers (2)

Roman Hwang
Roman Hwang

Reputation: 405

You can use From argument from handle_call or handle_info calls to get User, Server, Resource information. Then call:

Info = ejabberd_sm:get_user_info(User, Server, Resource), 
{ip, {Ip, Port}} = lists:keyfind(ip, 1, Info).

Upvotes: 0

andi5
andi5

Reputation: 1616

Depending on the size of your installation, you might want to run ejabberd_sm:dirty_get_sessions_list/0 and call get_user_ip/3 on each triple to implement a reverse lookup.

Upvotes: 1

Related Questions