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
Post a Comment