Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'else:': 0.03; 'implements': 0.05; 'instance': 0.05; 'attribute': 0.07; '%s"': 0.09; '__name__': 0.09; 'skip:[ 20': 0.12; 'def': 0.15; '"__main__":': 0.16; 'hashlib': 0.16; 'name):': 0.16; 'openssl': 0.16; 'perspective': 0.16; 'result:': 0.16; 'strange,': 0.16; 'subject:Twisted': 0.16; 'received:209.85.210.174': 0.18; 'received:mail-iy0-f174.google.com': 0.18; 'skip:m 30': 0.19; 'suggest': 0.20; 'wrote': 0.20; 'dictionary': 0.23; 'server.': 0.24; 'skip:l 30': 0.24; 'thanks.': 0.26; 'tried': 0.26; "i'm": 0.27; 'raise': 0.28; 'skip:p 30': 0.28; 'import': 0.28; 'message- id:@mail.gmail.com': 0.29; 'print': 0.29; 'log.': 0.30; 'class': 0.30; 'hi,': 0.32; 'to:addr:python-list': 0.33; "i've": 0.34; 'ssl': 0.34; 'could': 0.38; 'received:google.com': 0.38; 'received:209.85': 0.38; 'should': 0.38; 'non': 0.38; 'subject:: ': 0.39; 'client': 0.39; 'skip:z 10': 0.39; 'to:addr:python.org': 0.39; "it's": 0.40; 'skip:1 10': 0.63; 'here': 0.65; 'header :Reply-To:1': 0.71; 'reply-to:no real name:2**0': 0.71; 'factory': 0.73; 'skip:c 50': 0.77; 'andrea': 0.84; 'ip,': 0.84; 'factory,': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:reply-to:date:message-id:subject:from:to:content-type; bh=p8vCtIC6JvQf2ERVfYmwC7hIVhzUaClyhl8JvOA195A=; b=G1bjJVPK79Wt2nqXqyAV04A7LE+m0fH8y6gToEH2Luo6mMZ97LiAImNo006jmicnCO Z0vwRaVED7fLC87fTybTnM1bAO3NS6edQ6LFlqX0t2fvLN0sMU/ikBqafEnXA0NX4Feb Xj1kURkiw9Dqh0J5EmCP0AL3hbVVUuxaoASKw= MIME-Version: 1.0 Date: Wed, 14 Sep 2011 15:06:39 +0200 Subject: Twisted Perspective Broker: get client ip From: Andrea Di Mario To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: andrea.dimario@speakage.com List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 79 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1316005601 news.xs4all.nl 2514 [2001:888:2000:d::a6]:60861 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:13272 Hi, i'm writing a perspective broker server. Now, i should get the client IP, that perspective broker writes well in the log. I've tried to get it from MyRealm with: mind.broker.transport.getPeer(), without success. I've tried self.transport.getPeer() to, with this result: exceptions.AttributeError: Listner instance has no attribute 'transport' It's strange, because PB wrote the client IP, infact in log i've line with: 2011-09-11 16:41:58+0200 [Broker,0,127.0.0.1] ............ Could you suggest me something? Thanks. Here the code: from OpenSSL import SSL from twisted.internet import reactor, ssl from ConfigParser import SafeConfigParser from twisted.python import log from twisted.spread import pb from twisted.cred import checkers, portal from zope.interface import implements import hashlib class Listner(pb.Avatar): def __init__(self, name): self.name = name def perspective_getDictionary(self, dictionary): print dictionary def perspective_simplyAccess(self, access): print access def verifyCallback(connection, x509, errnum, errdepth, ok): if not ok: log.msg("Certificato non valido: %s" % x509.get_subject()) return False else: log.msg("Connessione stabilita, vertificato valido: %s" % x509.get_subject()) return True class MyRealm: implements(portal.IRealm) def requestAvatar(self, avatarId, mind, *interfaces): if pb.IPerspective not in interfaces: raise NotImplementedError return pb.IPerspective, Listner(avatarId), lambda:None if __name__ == "__main__": CONFIGURATION = SafeConfigParser() CONFIGURATION.read('server.conf') PORT = CONFIGURATION.get('general', 'port') LOGFILE = CONFIGURATION.get('general', 'log') log.startLogging(open(LOGFILE,'a')) myContextFactory = ssl.DefaultOpenSSLContextFactory(CONFIGURATION.get('general', 'keypath'), CONFIGURATION.get('general', 'certpath')) ctx = myContextFactory.getContext() ctx.set_verify(SSL.VERIFY_PEER | SSL.VERIFY_FAIL_IF_NO_PEER_CERT, verifyCallback) ctx.load_verify_locations(CONFIGURATION.get('general', 'cacert')) p = portal.Portal(MyRealm()) c = checkers.FilePasswordDB('passwords.txt', caseSensitive=True, cache=True) p.registerChecker(c) factory = pb.PBServerFactory(p) reactor.listenSSL(int(PORT), factory, myContextFactory) reactor.run() -- Andrea Di Mario