Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Error f = open(r'D:\NetAuto\myswitches.txt')
#1
Hi all,
This is my code:
import getpass
import sys
import telnetlib

user = raw_input("Enter your telnet username: ")
password = getpass.getpass()

f = open(r'D:\NetAuto\myswitches.txt')

for line in f:
	print "configuring Switch " + (line)
	HOST = line
	tn = telnetlib.Telnet(HOST)

tn.read_until("Username: ")
tn.write(user + "\n")
if password:
	tn.read_until("Password: ")
	tn.write(password + "\n")

tn.write("conf t\n")
	
for n in range(40,51):
	tn.write("vlan " + str(n) + "\n")
	tn.write("name Python_VLAN_" + str(n) + "\n")

	tn.write("end\n")
	tn.write("wr\n")
	tn.write("exit\n")
	
print tn.read_all()
But there are error for the code:
configuring Switch 192.168.1.101
Error:
Traceback (most recent call last): File "D:\NetAuto\Openfile.py", line 13, in <module> tn = telnetlib.Telnet(HOST) File "C:\Python27\lib\telnetlib.py", line 211, in __init__ self.open(host, port, timeout) File "C:\Python27\lib\telnetlib.py", line 227, in open self.sock = socket.create_connection((host, port), timeout) File "C:\Python27\lib\socket.py", line 557, in create_connection for res in getaddrinfo(host, port, 0, SOCK_STREAM): socket.gaierror: [Errno 11001] getaddrinfo failed
Please help me this error
Larz60+ wrote Apr-21-2020, 02:41 AM:
Please post all code, output and errors (in it's entirety) between their respective tags. I did it for you this time, Here are instructions on how to do it yourself next time.

Buran gave you a verbal warning about this on your last thread.
Next thread or post without heeding rules may bring hard warning.

Please read the rules bbcode section
Quote

Top Page

Forum Jump:


Users browsing this thread: 1 Guest(s)