Hi all,
This is my code:
But there are error for the code:
configuring Switch 192.168.1.101
This is my code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
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() |
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