0

how i can get the client IP in eventlet + WSGI, socketio when someone connects to the web socket AND when the client request any page on the site?? i tried what i can find in the internet, it doesn't seem to work with me

code:

import socketio
import logging


sio= socketio.Server()

app = socketio.WSGIApp(sio, static_files={
    '/': {'content_type': 'text/html', 'filename': '/home/*****/SecChat/index.html'}
})

#please be aware that what connects to the websocket is a python-client, not from the website 
#<socketio functionality (i deleted the code here as its not related)>

if __name__ == '__main__':
    eventlet.wsgi.server(eventlet.listen(('', 5000)), app, log=open(os.devnull,"w"))```
Shards-7
  • 23
  • 4

1 Answers1

0

In your connect handler you can access the IP address of the client with:

ip = environ['REMOTE_ADDR']

Note that environ is passed as an argument into your handler.

Miguel Grinberg
  • 65,299
  • 14
  • 133
  • 152