python - telnet to several devices and return command output -


i running python (ver. 2.6.2) on linux machine , need able telnet long list of devices (about 300) send command "sho ser" , return resulting output of command file , each sequential device down list add it's output new line. devices listed on separate lines in file

i found code got me started post not sure go here. can open list have called "hostlist" im not sure how tell python telnet 1 device, run command, exit, go next. appreciated

import getpass import sys import telnetlib  f = open('hostlist', 'r')  host = "%s" % f user = raw_input("enter login name: ") 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("show ver\n") tn.write("exit\n")  print tn.read_all() 

receiving error

enter login name: k3grb6hj9ld93a2 password:  traceback (most recent call last):  file "test.py", line 11, in <module>     tn = telnetlib.telnet(host)  file "/usr/lib/python2.6/telnetlib.py", line 209, in __init__     self.open(host, port, timeout)  file "/usr/lib/python2.6/telnetlib.py", line 225, in open     self.sock = socket.create_connection((host, port), timeout)  file "/usr/lib/python2.6/socket.py", line 498, in create_connection     res in getaddrinfo(host, port, 0, sock_stream):   socket.gaierror: [errno -2] name or service not known 


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -