473,789 Members | 2,447 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to know if connection is active when using telnetlib?

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


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.Telne t("blah")

----------
throws this exception:
----------
socket.gaierror : (11001, 'getaddrinfo failed')
----------
note that this is the same as your "telnetlib.Teln et.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.Telne t("blah")
except socket.gaierror :
print "host could not be found."
----------
Note that the "socket.gaierro r" is thrown when the hostname is invalid,
and "socket.err or" 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
2087
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
11194
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, this code returns the traceback that follows: import telnetlib host = 'nnn.nnn.nnn.nnn'
2
2415
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 logfiles. import telnetlib HOST = "192.X.X.X" user = "myname" password = "mypass"
4
10520
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 password is not realistic... I'm still in "proof of concept" stage here :) ######################### import telnetlib
2
7417
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. One sure shot way to find out this is by executing some dummy SELECT query and catching it via SQLException. This could be done in various DB's as follows: SELECT * from 1 (MS SQL) SELECT * from DUAL(Oracle)
2
4677
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 any new messages. The problem with this is that I poll at 2 second intervals (since connection is not active), and so its not as responsive as I'd like it to be. My question is, is an active HTTP connection possible? How did Meebo or Gmail...
1
8388
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 seen) that would allow me to log into a Cisco router, enter configuration mode, change an interface description and also grab a snapshot of the running configuration. So far I've managed to be able to log in and change the interface configuration....
3
3250
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
3738
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 application running in JBoss 4.0.1 where a standard DataSource in JBoss is defined for connections against a DB2 database on an AS/400 (VRM = V5R2M0). The driver is established as: <driver-...
0
9499
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10374
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10177
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10121
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9969
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5539
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4076
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3677
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.