So, I have this working now. I can send commands to the telnet server, dynamically. However, is there a way to supress the output of the data I get back so it doesn't flood my shell (stdout)?<br><br>Thanks,<br><br>Don<br><br>
<div><span class="gmail_quote">On 2/28/06, <b class="gmail_sendername">Alejandro J. Cura</b> <<a href="mailto:alecu@vortech.com.ar">alecu@vortech.com.ar</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
As you can see in twisted.internet.protocol.Factory<br><br> def buildProtocol(self, addr):<br> """Create an instance of a subclass of Protocol.<br><br> The returned instance will handle input on an incoming server
<br> connection, and an attribute \"factory\" pointing to the creating<br> factory.<br><br> Override this method to alter how Protocol instances get created.<br><br> @param addr: an object implementing
<br>L{twisted.internet.interfaces.IAddress}<br> """<br> p = self.protocol()<br> p.factory = self<br> return p<br><br>ReconnectingClientFactory inherits that method, so each TelnetClient
<br>instance it builds will have a self.factory you can use to access<br>your cmd list.<br><br>Hope that helps,<br>--<br>alecu<br><br>On 2/28/06, Don Smith <<a href="mailto:donwsmith@gmail.com">donwsmith@gmail.com</a>
> wrote:<br>> Yes, I'm sort of a Twisted newbie, so maybe this has an obvious answer, but<br>> I'm just not seeing it.<br>><br>> I have a Twisted program that I need to add in the ability to make a client<br>
> telnet connection to a remote server and send some commands to it and deal<br>> with the data received.<br>><br>> In my main program I have this line of code:<br>> reactor.connectTCP("mytelnethost", 24,
<br>> Connections.TelnetConnection("myname of object",events,"command to run"))<br>><br>> My Connections.TelnetConnection class looks like this:<br>><br>> from twisted.internet.protocol import Protocol, ReconnectingClientFactory
<br>> from twisted.conch.telnet import Telnet<br>><br>> class TelnetClient(Telnet):<br>> def connectionMade(self):<br>> print "connection made"<br>> self.write("\r\n")
<br>><br>> def write(self, data):<br>> print data<br>> Telnet._write(self, data+"\r\n")<br>><br>> def dataReceived(self, data):<br>> print "received:", data
<br>> if "User Name:" in data:<br>> self.write("user")<br>><br>> if "Password:" in data:<br>> self.write("password")<br>><br>><br>> if ">" in data:
<br>> time.sleep(2)<br>> self.write("connect")<br>> if "Connector Name:" in data:<br>> time.sleep(2)<br>> self.write("another command")<br>>
<br>><br>><br>> class TelnetConnection(Connection, ReconnectingClientFactory):<br>> """ Telnets to host:port and executes cmd. cmd """<br>> protocol = TelnetClient<br>> def __init__(self, name, eventQueue, cmd=None):
<br>> Connection.__init__(self, name)<br>><br>> def clientConnectionFailed(self, connector, reason):<br>> print 'connection failed:', reason.getErrorMessage()<br>><br>><br>> def clientConnectionLost(self, connector, reason):
<br>> print 'connection lost:', reason.getErrorMessage()<br>><br>><br>><br>> This all works great, except that the command sequence is hard coded in the<br>> TelnetClient class. I want to be able to reference the "cmd" parameter,
<br>> which could be a list of commands to iterate over,etc. But I don't see how I<br>> can access the "cmd" parameter that gets passed into the TelnetConnection<br>> class from within the TelnetClient class.
<br>><br>> I'm really desparate for some help, I've been racking my brain on this since<br>> yesterday morning.<br>><br>> Thanks,<br>><br>> Don<br>><br>><br>> _______________________________________________
<br>> Twisted-Python mailing list<br>> <a href="mailto:Twisted-Python@twistedmatrix.com">Twisted-Python@twistedmatrix.com</a><br>> <a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
</a><br>><br>><br>><br><br>_______________________________________________<br>Twisted-Python mailing list<br><a href="mailto:Twisted-Python@twistedmatrix.com">Twisted-Python@twistedmatrix.com</a><br><a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python">
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python</a><br></blockquote></div><br>