python - How to get server IP-address in Tornado? -


in tornado-based application need store server's ip-address (e.g. address used user connect server) in session. how determine ip-address in tornado? i'm using tornado 2.4.1.

if don't mind throwing in dependencies, can request handler:

import socket import urlparse      hostname = urlparse.urlparse("%s://%s"     % (self.request.protocol, self.request.host)).hostname  ip_address = socket.gethostbyname(hostname) 

an important thing note here self.request.host can include port number. that's why preferred parse using urlparse.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

python - Django-cities exits with "killed" -

python - How to get a widget position inside it's layout in Kivy? -