I’m writing a simple xmlrpc programe in python. something like the following:
def foo(data):
# I want get the calling client's IP address here... How can I ?
server=SimpleXMLRPCServer.SimpleXMLRPCServer((host, port))
server.register_function(foo)
server.handle_request()
As can be seen in the above, I want to get the client IP address in the registed function “foo”, how can I ?
You may do so by subclassing the server (and possibly the handler, too). E.g.:
Now server.client_address gives you the desired data. Note that this direct, short coding only works for the single-threaded case (which you’re using anyway by choosing the simple server in your code) — the need to work with the handler comes in if you want to go multi-threaded.