[newbie] trying socket as a replacement for nc

Jean Dubois jeandubois314 at gmail.com
Mon Dec 16 12:44:31 CET 2013


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



More information about the Python-list mailing list