~certify-web-dev/twisted/certify-staging

« back to all changes in this revision

Viewing changes to doc/howto/telnet.html

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2010-01-02 19:38:17 UTC
  • mfrom: (2.2.4 sid)
  • Revision ID: james.westby@ubuntu.com-20100102193817-jphp464ppwh7dulg
Tags: 9.0.0-1
* python-twisted: Depend on the python-twisted-* 9.0 packages.
* python-twisted: Depend on python-zope.interface only. Closes: #557781.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?xml version="1.0"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><title>Twisted Documentation: Using telnet to manipulate a twisted server</title><link href="stylesheet.css" type="text/css" rel="stylesheet" /></head><body bgcolor="white"><h1 class="title">Using telnet to manipulate a twisted server</h1><div class="toc"><ol></ol></div><div class="content"><span></span><p>To start things off, we're going to create a simple server that just
 
1
<?xml version="1.0" encoding="utf-8"?>
 
2
<!DOCTYPE html
 
3
  PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN'
 
4
  'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
 
5
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
 
6
  <head>
 
7
<title>Twisted Documentation: Using telnet to manipulate a twisted server</title>
 
8
<link href="stylesheet.css" rel="stylesheet" type="text/css"/>
 
9
  </head>
 
10
 
 
11
  <body bgcolor="white">
 
12
    <h1 class="title">Using telnet to manipulate a twisted server</h1>
 
13
    <div class="toc"><ol/></div>
 
14
    <div class="content">
 
15
<span/>
 
16
 
 
17
<p>To start things off, we're going to create a simple server that just
3
18
gives you remote access to a Python interpreter. We will use a telnet client
4
 
to access this server.</p><p>Run <code class="shell">twistd telnet -p 4040 -u admin -w admin</code> at
 
19
to access this server.</p>
 
20
 
 
21
<p>Run <code class="shell">twistd telnet -p 4040 -u admin -w admin</code> at
5
22
your shell prompt. The Application has a telnet server that you specified to 
6
23
be on port 4040, and it will start listening for connections on this port. Try 
7
 
connecting with your favorite telnet utility to 127.0.0.1 port 4040.</p><pre class="shell">
 
24
connecting with your favorite telnet utility to 127.0.0.1 port 4040.</p>
 
25
 
 
26
<pre class="shell" xml:space="preserve">
8
27
$ <em>telnet localhost 4040</em>
9
28
Trying 127.0.0.1...
10
29
Connected to localhost.
15
34
username: <em>admin</em>
16
35
password: <em>admin</em>
17
36
&gt;&gt;&gt;
18
 
</pre><p>Now, you should see a Python prompt --
 
37
</pre>
 
38
 
 
39
<p>Now, you should see a Python prompt --
19
40
<code>&gt;&gt;&gt;</code>. You can type any valid Python code
20
 
here. Let's try looking around.</p><pre class="python-interpreter">
 
41
here. Let's try looking around.</p>
 
42
 
 
43
<pre class="python-interpreter" xml:space="preserve">
21
44
&gt;&gt;&gt; <em>dir()</em>
22
45
['__builtins__']
23
 
</pre><p>Ok, not much. let's play a little more:</p><pre class="python-interpreter">
 
46
</pre>
 
47
 
 
48
<p>Ok, not much. let's play a little more:</p>
 
49
<pre class="python-interpreter" xml:space="preserve">
24
50
&gt;&gt;&gt; <em>import __main__</em>
25
51
&gt;&gt;&gt; <em>dir(__main__)</em>
26
52
['__builtins__', '__doc__', '__name__', 'os', 'run', 'string', 'sys']
31
57
&lt;twisted.manhole.telnet.ShellFactory on 4040&gt;
32
58
&gt;&gt;&gt; <em>service.parent</em>
33
59
&lt;twisted.application.service.MultiService instance at 0x1024d7a8&gt;
34
 
</pre><p>The service object is the service used to serve the telnet shell,
 
60
</pre>
 
61
 
 
62
<p>The service object is the service used to serve the telnet shell,
35
63
and that it is listening on port 4040 with something called a
36
 
<code class="API"><a href="http://twistedmatrix.com/documents/8.2.0/api/twisted.manhole.telnet.ShellFactory.html" title="twisted.manhole.telnet.ShellFactory">ShellFactory</a></code>. 
 
64
<code class="API"><a href="http://twistedmatrix.com/documents/9.0.0/api/twisted.manhole.telnet.ShellFactory.html" title="twisted.manhole.telnet.ShellFactory">ShellFactory</a></code>. 
37
65
Its parent is a <code class="python">twisted.application.service.MultiService</code>,
38
66
a collection of services. We can keep getting the parent attribute
39
 
of services until we hit the root of all services.</p><p>As you can see, this is quite useful - we can introspect a
 
67
of services until we hit the root of all services.</p>
 
68
 
 
69
<p>As you can see, this is quite useful - we can introspect a
40
70
running process, see the internal objects, and even change
41
71
their attributes. The telnet server can of course be used from straight 
42
72
Python code; you can see how to do this by reading the code for 
43
 
<code class="API"><a href="http://twistedmatrix.com/documents/8.2.0/api/twisted.tap.telnet.html" title="twisted.tap.telnet">twisted.tap.telnet</a></code>.</p><p>A final note - if you want access to be more secure, you can even
 
73
<code class="API"><a href="http://twistedmatrix.com/documents/9.0.0/api/twisted.tap.telnet.html" title="twisted.tap.telnet">twisted.tap.telnet</a></code>.</p>
 
74
 
 
75
<p>A final note - if you want access to be more secure, you can even
44
76
have the telnet server use SSL. Assuming you have the appropriate
45
77
certificate and private key files, you can <code class="shell">twistd
46
78
telnet -p ssl:443:privateKey=mykey.pem:certKey=cert.pem -u admin -w
47
 
admin</code>.  See <code class="API"><a href="http://twistedmatrix.com/documents/8.2.0/api/twisted.application.strports.html" title="twisted.application.strports">twisted.application.strports</a></code> for more examples of
48
 
options for listening on a port.</p></div><p><a href="index.html">Index</a></p><span class="version">Version: 8.2.0</span></body></html>
 
 
b'\\ No newline at end of file'
 
79
admin</code>.  See <code class="API"><a href="http://twistedmatrix.com/documents/9.0.0/api/twisted.application.strports.html" title="twisted.application.strports">twisted.application.strports</a></code> for more examples of
 
80
options for listening on a port.</p>
 
81
 
 
82
</div>
 
83
 
 
84
    <p><a href="index.html">Index</a></p>
 
85
    <span class="version">Version: 9.0.0</span>
 
86
  </body>
 
87
</html>
 
 
b'\\ No newline at end of file'