[Twisted-Python] getPeer() inside conch
Benjamin Rutt
rutt.4 at osu.edu
Tue Sep 29 17:16:44 MDT 2009
The code:
print 'hello, peer %s' % (self.terminal.transport.getPeer())
Fails with:
AttributeError: SSHSessionProcessProtocol instance has no attribute
'getPeer'
One possible patch to twisted 8.2.0's conch/ssh/session.py's
SSHSessionProcessProtocol class to add a getPeer() method would be:
$ diff -u session.py.orig session.py
--- session.py.orig 2009-06-10 06:30:33.000000000 -0400
+++ session.py 2009-09-29 12:30:01.622444000 -0400
@@ -13,7 +13,7 @@
import struct
-from twisted.internet import protocol
+from twisted.internet import protocol, address
from twisted.python import log
from twisted.conch.interfaces import ISession
from twisted.conch.ssh import common, channel
@@ -210,6 +210,10 @@
def loseConnection(self):
self.session.loseConnection()
+ def getPeer(self):
+ client = self.session.conn.transport.transport.client
+ return address.IPv4Address('TCP', client[0], client[1])
+
class SSHSessionClient(protocol.Protocol):
def dataReceived(self, data):
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20090929/e9cc4bcb/attachment.html>
More information about the Twisted-Python
mailing list