Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #62039 > unrolled thread
| Started by | Jean-Michel Pichavant <jeanmichel@sequans.com> |
|---|---|
| First post | 2013-12-16 11:29 +0100 |
| Last post | 2013-12-16 03:44 -0800 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.python
Re: [newbie] trying socket as a replacement for nc Jean-Michel Pichavant <jeanmichel@sequans.com> - 2013-12-16 11:29 +0100
Re: [newbie] trying socket as a replacement for nc Jean Dubois <jeandubois314@gmail.com> - 2013-12-16 03:44 -0800
| From | Jean-Michel Pichavant <jeanmichel@sequans.com> |
|---|---|
| Date | 2013-12-16 11:29 +0100 |
| Subject | Re: [newbie] trying socket as a replacement for nc |
| Message-ID | <mailman.4197.1387189761.18130.python-list@python.org> |
> > Such equipment often implements a telnet protocol. Have use try
> > using the telnetlib module ?
> > http://docs.python.org/2/library/telnetlib.html
> >
> > t = Telnet(host, port)
> > t.write('*IDN?')
> > print t.read_until('Whateverprompt')
> > # you can use read_very_eager also
> >
> > JM
> >
> >
> Could you tell me how to install telnetlib on a linux-system (it's
> not
> available via apt-get install as I see it)
>
> kind regards,
> jean
>
Please keep it on list, some other may have the same install issue or someone could have better insights on installing telnetlib.
telnetlib is part of the standard modules in my Debian squeeze(python 2.5). Looking at the doc, it looks like it's available for python 3 as well. Strange that you don't have it.
Did you try
import telnetlib
?
Note that in the code above I forgot the EOF, which is very much dependent of the equipment itself.
You may have to write
t.write('*IDN?\n')
or
t.write('IDN?\n\r')
JM
-- IMPORTANT NOTICE:
The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.
[toc] | [next] | [standalone]
| From | Jean Dubois <jeandubois314@gmail.com> |
|---|---|
| Date | 2013-12-16 03:44 -0800 |
| Message-ID | <aabaa0e5-7f13-47c8-b81c-6b9a9e3785de@googlegroups.com> |
| In reply to | #62039 |
Op maandag 16 december 2013 11:29:12 UTC+1 schreef Jean-Michel Pichavant:
> > > Such equipment often implements a telnet protocol. Have use try
> > > using the telnetlib module ?
> > > http://docs.python.org/2/library/telnetlib.html
> > >
> > > t = Telnet(host, port)
> > > t.write('*IDN?')
> > > print t.read_until('Whateverprompt')
> > > # you can use read_very_eager also
> > >
> > > JM
> > >
> > >
> > Could you tell me how to install telnetlib on a linux-system (it's
> > not
> > available via apt-get install as I see it)
> >
> > kind regards,
> > jean
> >
> Please keep it on list, some other may have the same install issue or someone could have better insights on installing telnetlib.
> telnetlib is part of the standard modules in my Debian squeeze(python 2.5). Looking at the doc, it looks like it's available for python 3 as well. Strange that you don't have it.
> Did you try
> import telnetlib
> ?
> Note that in the code above I forgot the EOF, which is very much dependent of the equipment itself.
> You may have to write
> t.write('*IDN?\n')
> or
> t.write('IDN?\n\r')
> JM
Here is the code:
#!/usr/bin/env python
import telnetlib
host = '10.128.59.63'
port = 7000
t = Telnet(host, port)
t.write('*IDN?\n')
print t.read_until('Whateverprompt')
# you can use read_very_eager also
and this is the result of executing the code(from which I deduce I have to
install telnetlib, but how?)
Traceback (most recent call last):
File "./nctelnet.py", line 5, in <module>
t = Telnet(host, port)
NameError: name 'Telnet' is not defined
kind regards,
jean
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web