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> &lt;<a href="mailto:alecu@vortech.com.ar">alecu@vortech.com.ar</a>&gt; 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>&nbsp;&nbsp;&nbsp;&nbsp;def buildProtocol(self, addr):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;&quot;&quot;Create an instance of a subclass of Protocol.<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The returned instance will handle input on an incoming server
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;connection, and an attribute \&quot;factory\&quot; pointing to the creating<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;factory.<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Override this method to alter how Protocol instances get created.<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@param addr: an object implementing
<br>L{twisted.internet.interfaces.IAddress}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;&quot;&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p = self.protocol()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p.factory = self<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return p<br><br>ReconnectingClientFactory inherits that method, so each TelnetClient
<br>instance it builds will&nbsp;&nbsp;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 &lt;<a href="mailto:donwsmith@gmail.com">donwsmith@gmail.com</a>
&gt; wrote:<br>&gt; Yes, I'm sort of a Twisted newbie, so maybe this has an obvious answer, but<br>&gt; I'm just not seeing it.<br>&gt;<br>&gt; I have a Twisted program that I need to add in the ability to make a client<br>
&gt; telnet connection to a remote server and send some commands to it and deal<br>&gt; with the data received.<br>&gt;<br>&gt; In my main program I have this line of code:<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; reactor.connectTCP(&quot;mytelnethost&quot;, 24,
<br>&gt; Connections.TelnetConnection(&quot;myname of object&quot;,events,&quot;command to run&quot;))<br>&gt;<br>&gt; My Connections.TelnetConnection class looks like this:<br>&gt;<br>&gt; from twisted.internet.protocol import Protocol, ReconnectingClientFactory
<br>&gt; from twisted.conch.telnet import Telnet<br>&gt;<br>&gt; class TelnetClient(Telnet):<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; def connectionMade(self):<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &quot;connection made&quot;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; self.write(&quot;\r\n&quot;)
<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; def write(self, data):<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; print data<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; Telnet._write(self, data+&quot;\r\n&quot;)<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; def dataReceived(self, data):<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &quot;received:&quot;, data
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; if &quot;User Name:&quot; in data:<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.write(&quot;user&quot;)<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; if &quot;Password:&quot; in data:<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.write(&quot;password&quot;)<br>&gt;<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; if &quot;&gt;&quot; in data:
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; time.sleep(2)<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.write(&quot;connect&quot;)<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; if &quot;Connector Name:&quot; in data:<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;time.sleep(2)<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.write(&quot;another command&quot;)<br>&gt;
<br>&gt;<br>&gt;<br>&gt; class TelnetConnection(Connection, ReconnectingClientFactory):<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &quot;&quot;&quot; Telnets to host:port and executes cmd. cmd &quot;&quot;&quot;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; protocol = TelnetClient<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; def&nbsp;&nbsp;__init__(self, name, eventQueue, cmd=None):
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Connection.__init__(self, name)<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; def clientConnectionFailed(self, connector, reason):<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print 'connection failed:', reason.getErrorMessage()<br>&gt;<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; def clientConnectionLost(self, connector, reason):
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print 'connection lost:', reason.getErrorMessage()<br>&gt;<br>&gt;<br>&gt;<br>&gt; This all works great, except that the command sequence is hard coded in the<br>&gt; TelnetClient class. I want to be able to reference the &quot;cmd&quot; parameter,
<br>&gt; which could be a list of commands to iterate over,etc. But I don't see how I<br>&gt; can access the &quot;cmd&quot; parameter that gets passed into the TelnetConnection<br>&gt; class from within the TelnetClient class.
<br>&gt;<br>&gt; I'm really desparate for some help, I've been racking my brain on this since<br>&gt; yesterday morning.<br>&gt;<br>&gt; Thanks,<br>&gt;<br>&gt; Don<br>&gt;<br>&gt;<br>&gt; _______________________________________________
<br>&gt; Twisted-Python mailing list<br>&gt; <a href="mailto:Twisted-Python@twistedmatrix.com">Twisted-Python@twistedmatrix.com</a><br>&gt; <a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
</a><br>&gt;<br>&gt;<br>&gt;<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>