Flask-socketio: Is there a way to get the IP address of each client?

Created on 28 May 2017  路  2Comments  路  Source: miguelgrinberg/Flask-SocketIO

I'd like a way to be able to grab the IP addresses of clients as they connect or when they send a command, and so far I haven't found a way online; is there a way?

question

Most helpful comment

You can do this in the usual Flask way, using the request object. The request.remote_addr attribute contains the IP address of the client. But if you are using a reverse proxy, then remote_addr is always going to be the address of your proxy. In this case, the ProxyFix middleware may be of help.

All 2 comments

You can do this in the usual Flask way, using the request object. The request.remote_addr attribute contains the IP address of the client. But if you are using a reverse proxy, then remote_addr is always going to be the address of your proxy. In this case, the ProxyFix middleware may be of help.

Ahh I see. The proxy issue must by why it didn't work when I tried..

Cheers.

Was this page helpful?
0 / 5 - 0 ratings