How to get client IP address?

I need to get the client IP address, this does not work:

def create(conn) do ip_address = conn.inet.ip_address # .... 

due to key :inet not found in: %Plug.Conn . How can I get an IP address?

+5
source share
2 answers

Mark the request fields :

remote_ip - client IP address, for example: {151, 236, 219, 228}. This field is for overwriting with forks that understand, for example. X-Forwarded-For header or HAProxys PROXY protocol. By default, it sets IP addresses.

This is what you are looking for:

 conn.remote_ip 
+8
source

Get IP:

conn.remote_ip

Casting from ip_address to a string:

to_string(:inet_parse.ntoa(conn.remote_ip))

+4
source

Source: https://habr.com/ru/post/1258577/


All Articles