Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IP address of client in Python SimpleXMLRPCServer?

I have a SimpleXMLRPCServer server (Python).

How can I get the IP address of the client in the request handler?

This information appears in the log. However, I am not sure how to access this information from within the request handler.

like image 244
Joseph Turian Avatar asked Jan 23 '23 16:01

Joseph Turian


2 Answers

As Michael noted, you can get client_address from within the request handler. For instance, you can override the __init__ function which is inherited indirectly from BaseRequestHandler.

class RequestHandler(SimpleXMLRPCRequestHandler):
    def __init__(self, request, client_address, server):
        print client_address # do what you need to do with client_address here
        SimpleXMLRPCRequestHandler.__init__(self, request, client_address, server)
like image 160
Nick Russo Avatar answered Jan 25 '23 05:01

Nick Russo


The request handler itself should have a property client_address (inherited from BaseHTTPRequestHandler). From BaseHTTPRequestHandler:

Contains a tuple of the form (host, port) referring to the client’s address.

like image 36
Michael Avatar answered Jan 25 '23 05:01

Michael