473,322 Members | 1,778 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

How to know if connection is active when using telnetlib?

How to know if connection is active after telnetlib.Telnet.open(host,port)?
Aug 26 '05 #1
3 12389
Wojciech Halicki-Piszko <wh*@wp.pl> writes:
How to know if connection is active after telnetlib.Telnet.open(host,port)?


If open() doesn't throw an exception then you should have a connection you can
start reading/writing with. Unless you have some special meaning for
'active'?

I'm just basing this on reading telnetlib.py.

Eddie
Aug 26 '05 #2
Well, running this code:
----------
import telnetlib
c = telnetlib.Telnet("blah")

----------
throws this exception:
----------
socket.gaierror: (11001, 'getaddrinfo failed')
----------
note that this is the same as your "telnetlib.Telnet.open". So, you
will want to use TRY: and EXCEPT: to catch those errors, as in the
example code below...
----------
import telnetlib
try:
c = telnetlib.Telnet("blah")
except socket.gaierror:
print "host could not be found."
----------
Note that the "socket.gaierror" is thrown when the hostname is invalid,
and "socket.error" is thrown when the connection is refused. If you try
to perform a "read" operation on a closed socket, you'll get thrown a
"EOFerror" or you may get a Null value. You'll have to handle each
case. I would suggest referring to the documentation at
"http://www.python.org/doc/2.4/lib/telnet-objects.html" for more
information about errors / exceptions returned. If there is none
specified, chances are, it will throw a "socket.*" exception, or a Null
value.

Aug 26 '05 #3
> If open() doesn't throw an exception then you should have a connection you can
start reading/writing with. Unless you have some special meaning for
'active'?

I'm just basing this on reading telnetlib.py.

Eddie


Well, in fact what I meant is: I won't to check wether established
connection is still active. I have a reading thread and when I send 'quit'
command to a server it (guess what:)) disconnects. So I get plenty of
unwanted output, I want to avoid this. So the problem is how can I inform
my reader thread it is not longer wanted when _server_ disconnects me? To
my defense: repetition is mother of science (in case you did answer and I
did not get it first time).

Aug 26 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: ÕÅÖ¾Ã÷ | last post by:
code below cannt work import getpass import sys import telnetlib import select tn = telnetlib.Telnet() print tn.open("162.105.31.222",23)
4
by: Donnal Walter | last post by:
On Windows XP I am able to connect to a remote telnet server from the command prompt using: telnet nnn.nnn.nnn.nnn 23 where nnn.nnn.nnn.nnn is the IP address of the host. But using telnetlib,...
2
by: Nitin Chaumal | last post by:
I sarched the existing threads but didnt find an answer to this. I am writing simple script which uses telentlib to open a session with a unix machine and run "tail -f logfile.txt" on one of the...
4
by: vercingetorix52 | last post by:
I'm trying to use a python script to access an embedded computer running linux and connected via a crossover ethernet cable using the following script... ....and I realize the username and...
2
by: Venkata Narayana | last post by:
Hi, You all may be knowing that Connection.isClosed() does not tells us if the underying DB connection is active or not; it only checks if Connection.close() had been previously called or not....
2
by: jason.m.ho | last post by:
Hello! I am trying to build an ajax chat system. Currently I have it so that when you chat, you upload your message to the database, and each client is polling that database to see if he/she has...
1
by: dudds | last post by:
Hi Guys, I just started learning Python a couple of days ago and to put some of what I learnt into practice. As such I thought I might try and write a simple program (based on examples I had...
3
by: Phoe6 | last post by:
Hi All, I am trying to use the telnetlib module. Manually when I do telnet 172.31.128.244 I get: Login: (I type root) Password: ( I type Password) And it enters to the Telnet Session:
1
by: hal9000cr | last post by:
We are running into some problems with the execution of DB2 stored procedures when their isolation level is set to: set transaction isolation level READ UNCOMMITTED, READ WRITE; This is a web...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.