telnetlib

python telnet and put the message in a particular log file

[亡魂溺海] 提交于 2019-12-08 07:36:27
hi I am coding the python script to login telnet and it has to write log file to op.txt the absolute path is /netperf/mntpt/array1/home/prg_use/op.txt the python code ptlog.py import getpass import sys import telnetlib import time host ="12.12.1.123" user ="user_name" passwd ="telnet_password" tn = telnetlib.Telnet(host) tn.read_until("login: ") tn.write(user + "\n") tn.read_until("Password: ") tn.write(passwd + "\n") tn.write("touch op.txt \n") time.sleep(5) tn.write("lr \n") str_all=tn.read_until("$") #f=open("/netperf/mntpt/array1/home/prg_use/op.txt", "w") f=open("op.txt", "w") f.write(str

cannot parallelize (threads) telnet connections with python

孤人 提交于 2019-12-08 01:54:31
问题 I have a code that will connect to several routers, using the telentlib, run some code within those, and finally write the output to a file. It runs smoothly. However, when I had to access lots of routers (+50) the task consumes a lot of time (the code runs serially, one router at a time). I thought then on implementing threads in order to accelerate the process. This is pretty much the code (just a snippet of it): # We import the expect library for python import telnetlib import sys import

cannot parallelize (threads) telnet connections with python

让人想犯罪 __ 提交于 2019-12-06 09:32:53
I have a code that will connect to several routers, using the telentlib, run some code within those, and finally write the output to a file. It runs smoothly. However, when I had to access lots of routers (+50) the task consumes a lot of time (the code runs serially, one router at a time). I thought then on implementing threads in order to accelerate the process. This is pretty much the code (just a snippet of it): # We import the expect library for python import telnetlib import sys import csv import time import threading # --- Timers TimeLogin = 10 TelnetWriteTimeout = 1 TelnetReadTimeout =

Detect a closed connection in python's telnetlib

冷暖自知 提交于 2019-12-05 14:56:30
I'm using python's telnetlib to connect to a remote telnet server. I'm having a hard time detecting if the connection is still open, or if the remote server closed it on me. I will notice the connection is closed the next time I try to read or write to it, but would like to have a way to detect it on demand. Is there a way to send some sort of an 'Are You There' packet without affecting the actual connection? The telnet RFC supports an "are you there" and "NOP" commands - just not sure how to get telnetlib to send them! You should be able to send a NOP this way: from telnetlib import IAC, NOP

Python telnetlib: surprising problem

喜欢而已 提交于 2019-12-04 11:37:16
I am using the Python module telnetlib to create a telnet session (with a chess server), and I'm having an issue I really can't wrap my brain around. The following code works perfectly: >>> f = login("my_server") #code for login(host) below. >>> f.read_very_eager() This spits out everything the server usually prints upon login. However, when I put it inside a function and then call it thus: >>> def foo(): ... f = login("my_server") ... return f.read_very_eager() ... >>> foo() I get nothing (the empty string). I can check that the login is performed properly, but for some reason I can't see the

Python multiple telnet sessions

浪子不回头ぞ 提交于 2019-12-04 04:15:35
问题 I need to build a script to get the telnet output of as many hosts as possible and save them to a separate file for each host. The script should run as a daemon. For the moment i have a function that encapsulates the logic for do it for a single host with telnetlib , but i do not how to proceed. I planned to open a process ( multiprocessing.Process ) for each host but i suspect it's going to be a resource waste and it must to exist a better way :) def TelnetLogSaver(hostname,ip,filename): #

Python multiple telnet sessions

霸气de小男生 提交于 2019-12-01 19:45:35
I need to build a script to get the telnet output of as many hosts as possible and save them to a separate file for each host. The script should run as a daemon. For the moment i have a function that encapsulates the logic for do it for a single host with telnetlib , but i do not how to proceed. I planned to open a process ( multiprocessing.Process ) for each host but i suspect it's going to be a resource waste and it must to exist a better way :) def TelnetLogSaver(hostname,ip,filename): # open files and telnet sessions f = open(filename,"a") tn = telnetlib.Telnet(ip,23,TIMEOUT) # login e =

Accessing a telnet session in python

半腔热情 提交于 2019-11-29 05:08:54
so I need to access a telnet session. More specifically JPL's ephemeris service. I know exactly what I need to do in the command prompt, but I've had trouble using the telnetlib package. Here are the steps I need to take through command prompt: telnet o horizons.jpl.nasa.gov 6775 DES=C/2012 X1; y E o H06 y 2013-Nov-7 9:00 2013-Nov-17 9:00 1d y 1,4,9,19,20,24 and then after that there is a large output that I need to save to a text file, or simply keep as a variable. I'll be using it later. And following these inputs step by step should get you to the exact bit of information I need to grab Any

telnetlib python example

扶醉桌前 提交于 2019-11-28 06:35:07
So I'm trying this really simple example given by the python docs: import getpass import sys import telnetlib HOST = "<HOST_IP>" user = raw_input("Enter your remote account: ") password = getpass.getpass() tn = telnetlib.Telnet(HOST) tn.read_until("login: ") tn.write(user + "\n") if password: tn.read_until("Password: ") tn.write(password + "\n") tn.write("ls\n") tn.write("exit\n") print tn.read_all() My issue is that it hangs at the end of the read_all()... It doesn't print anything out. I've never used this module before so I'm trying to get this really basic example to work before continuing

Accessing a telnet session in python

让人想犯罪 __ 提交于 2019-11-27 22:44:02
问题 so I need to access a telnet session. More specifically JPL's ephemeris service. I know exactly what I need to do in the command prompt, but I've had trouble using the telnetlib package. Here are the steps I need to take through command prompt: telnet o horizons.jpl.nasa.gov 6775 DES=C/2012 X1; y E o H06 y 2013-Nov-7 9:00 2013-Nov-17 9:00 1d y 1,4,9,19,20,24 and then after that there is a large output that I need to save to a text file, or simply keep as a variable. I'll be using it later.