obtain client ip address from SimpleXMLRPCServer ?

S

stuff

Is it possible to obtain the client's ip address from a
SimpleXMLRPCServer instance or subclass instance? When running
SimpleXMLRPCServer with logRequests = 1, the xmlrpc server prints out
the fqdn on the console, however, I'm not sure if this information
(either fqdn or ip address) is available to the SimpleXMLRPCServer
instance. Can somebody shed some light on how to obtain this
information?

Thanks,

Phil
 
P

Peter Gsellmann

Is it possible to obtain the client's ip address from a
SimpleXMLRPCServer instance or subclass instance? When running
SimpleXMLRPCServer with logRequests = 1, the xmlrpc server prints out
the fqdn on the console, however, I'm not sure if this information
(either fqdn or ip address) is available to the SimpleXMLRPCServer
instance. Can somebody shed some light on how to obtain this
information?
The request-handler has the method: address_string()

Peter
 
S

stuff

Thanks for the reply Peter. Can you provide a code snippet for
extracting this data. When I print the dir() of the SimpleXMLRPCServer
instance I do not see a request_handler attribute or method.

Phil
 
P

Peter Gsellmann

Thanks for the reply Peter. Can you provide a code snippet for
extracting this data. When I print the dir() of the SimpleXMLRPCServer
instance I do not see a request_handler attribute or method.
this is ok.
In the serverclass-object, there is no such method because the server
doesn't know which client would connect. It is a long-life object.

Each time a client connects the server creates another sort of object,
the so-called request-handler. This is a short-live object which terminates
when the request is answered. Only this object has knowledge of the client
as it holds the connection.

If you make a subclass of SimpleXMLRPCRequestHandler you can add or
override methods and add a line like this:
print self.address_string()

A sample for such subclassing is given in the file SimpleXMLRPCServer.py
itself. (usually in /usr/lib/python/ )

Peter
 
S

stuff

Thanks again Peter. I found 2 potential solutions for obtaining the ip
address of the incoming
connection. The first was to subclass SimpleXMLRPCRequestHandler class
and pass it
to the SimpleXMLRPCServer constructor. In doing so, I could directly
access the client_address via self.client_address. This worked just
fine but was a bit overkill.

The other solution I noticed was that SimpleXMLRPCServer's (which
ultimately subclasses BaseServer) handle_request method invokes
get_request (which merely calls self.socket.accept() -- which returns a
tuple including the ip address). By re-implementing get_request() as
such:

def get_request(self):
req = self.socket.accept()
ip_address = req[1][0]
return req

I can grab the ip address for internal use and have the get_request
method return the expected data for use by hande_request().

Now I just need to find a thread-safe way of passing this data back to
the XMLRPC server's registered_instance.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,217
Latest member
IRMNikole

Latest Threads

Top