开发者

How to get Peer IP Address in Nitrogen

Is is there a built in function in nitrogen framework to get P开发者_如何学Ceer IP address? If not, is there a way to get the IP address of peer which is making to request to Nitrogen App


You can get the remote peer's address using wf_platform:get_peername/0.

@spec wf_platform:get_peername() -> {ok, {Address, Port}} | {error, posix()}
    Address = {N1,N2,N3,N4} | {K1,K2,K3,K4,K5,K6,K7,K8}
    Port = int()


As of Nitrogen2, the function to do this is wf:peer_ip/0. It doesn't seem to appear in any docs at the moment, but it does almost the same thing wf_platform:get_peername() used to.

wf:peer_ip/0 -> {A, B, C, D} | {A, B, C, D, E, F, G, H} 
%% example output: {127, 0, 0, 1}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜