<div>The code:</div><div><br></div><div> print 'hello, peer %s' % (self.terminal.transport.getPeer())</div><div><br></div><div>Fails with:</div><div><br></div><div> AttributeError: SSHSessionProcessProtocol instance has no attribute 'getPeer'</div>
<div><br></div><div>One possible patch to twisted 8.2.0's conch/ssh/session.py's SSHSessionProcessProtocol class to add a getPeer() method would be:</div><div><br></div><div>$ diff -u session.py.orig session.py </div>
<div>--- session.py.orig 2009-06-10 06:30:33.000000000 -0400 </div><div>+++ session.py 2009-09-29 12:30:01.622444000 -0400 </div><div>@@ -13,7 +13,7 @@ </div><div> </div><div> import struct </div><div> </div><div>-from twisted.internet import protocol </div>
<div>+from twisted.internet import protocol, address </div><div> from twisted.python import log </div><div> from twisted.conch.interfaces import ISession </div><div> from twisted.conch.ssh import common, channel </div><div>
@@ -210,6 +210,10 @@ </div><div> def loseConnection(self): </div><div> self.session.loseConnection() </div><div> </div><div>+ def getPeer(self): </div><div>+ client = self.session.conn.transport.transport.client </div>
<div>+ return address.IPv4Address('TCP', client[0], client[1]) </div><div>+ </div><div> class SSHSessionClient(protocol.Protocol): </div><div> </div><div> def dataReceived(self, data):</div><div><br></div>
<div>Could someone comment on this? (I'm fairly certain ssh runs over TCP, but less certain that the mouthful self.session.conn.transport.transport.client isn't invading layers of abstraction in an unfriendly way). Thanks.</div>
<br>