obtain client ip address from SimpleXMLRPCServer ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • stuff@mailzilla.net

    #1

    obtain client ip address from SimpleXMLRPCServer ?

    Is it possible to obtain the client's ip address from a
    SimpleXMLRPCSer ver instance or subclass instance? When running
    SimpleXMLRPCSer ver 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 SimpleXMLRPCSer ver
    instance. Can somebody shed some light on how to obtain this
    information?

    Thanks,

    Phil

  • Peter Gsellmann

    #2
    Re: obtain client ip address from SimpleXMLRPCSer ver ?

    stuff@mailzilla .net wrote:
    [color=blue]
    > Is it possible to obtain the client's ip address from a
    > SimpleXMLRPCSer ver instance or subclass instance? When running
    > SimpleXMLRPCSer ver 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 SimpleXMLRPCSer ver
    > instance. Can somebody shed some light on how to obtain this
    > information?
    >[/color]
    The request-handler has the method: address_string( )

    Peter

    Comment

    • stuff@mailzilla.net

      #3
      Re: obtain client ip address from SimpleXMLRPCSer ver ?

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

      Phil

      Comment

      • Peter Gsellmann

        #4
        Re: obtain client ip address from SimpleXMLRPCSer ver ?

        stuff@mailzilla .net wrote:
        [color=blue]
        > Thanks for the reply Peter. Can you provide a code snippet for
        > extracting this data. When I print the dir() of the SimpleXMLRPCSer ver
        > instance I do not see a request_handler attribute or method.[/color]
        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 SimpleXMLRPCReq uestHandler you can add or
        override methods and add a line like this:
        print self.address_st ring()

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

        Peter

        Comment

        • stuff@mailzilla.net

          #5
          Re: obtain client ip address from SimpleXMLRPCSer ver ?

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

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

          def get_request(sel f):
          req = self.socket.acc ept()
          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_inst ance.

          Comment

          Working...