Python Forum
socket.gaierror: [Errno 11001]
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
socket.gaierror: [Errno 11001]
#1
Hello everyone. In my path to learning Python I want to use the code mentioned to telnet into 3 different switches with different IP addresses and add vlan 5,6 and name those vlans.
The IP addresses are saved in a separate file called ips.txt which is saved in the same folder as the code itself and the IPs are written under each other with no empty line in between. This is in GNS3 and from my virtual Windows I can ping switches with the IPs mentioned in ips.txt. So connectivity is not an issue. I can execute other version of this code where I added the IP addresses inside the code without using any extra file (ips.txt)but if the IPs are not sequential it is easier to make a file and call it in your code. By the way I am running Python 2.7


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

file = 'ips.txt'
with open(file) as f:
    for line in f:
        print " configuring the host " +  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("enable\n")
        tn.write("Cisco\n")
        tn.write("conf t\n")
        for x in range(5, 7):
            tn.write("vlan " + str(x) + "\n")
            tn.write("name python_vlan " + str(x) + "\n")
        tn.write("end\n")
        tn.write("wr\n")
        tn.write("exit\n")
        
        print tn.read_all()
Error:
Traceback (most recent call last): File "multiple_switches_ver2.py" , line 12, in <module> tn = telnetlib.Telnet(HOST) File "c:\Python27\lib\telnetlib.py", line 211, in __int__ 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\telnetlib.py", line 557, in create_connection for res in getaddrinfo(host, port, 0, SOCK_STREAM): socket.gaierror: [Errno 11001] getaddrinfo failed
Output:
Enter your telnet username: john password: configuring the host 192.168.122.11
Right after the output comes the error mentioned above. The output shows that the code through the ips.txt and 192.168.122.11 is the first IP in the file and it stops there without doing anything on any of the switches.
Reply


Messages In This Thread
socket.gaierror: [Errno 11001] - by Johnygo - Aug-06-2019, 06:40 PM
RE: socket.gaierror: [Errno 11001] - by Johnygo - Aug-06-2019, 08:14 PM
RE: socket.gaierror: [Errno 11001] - by DeaD_EyE - Aug-07-2019, 09:09 AM
RE: socket.gaierror: [Errno 11001] - by Johnygo - Aug-07-2019, 02:49 PM
RE: socket.gaierror: [Errno 11001] - by nemat - Nov-03-2019, 08:52 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  socket.gaierror: [Errno -2] Name or service not known seokangwoo99 5 15,822 May-25-2019, 02:36 PM
Last Post: DeaD_EyE
  socket.gaierror: [Errno -2] Name or Service not known ItsAGuyaneseTing 1 11,658 Mar-02-2018, 07:14 PM
Last Post: mpd

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020