Python - Telnetlib socket.gaierror:

Khailz

I am trying to create a telnet to Teamspeak 3 Server Query through python, this is my code:

__author__ = 'Khailz'

import telnetlib, socket

HOST = "unlightedgaming.com"
port = 10011
timeout = 5



for i in range(len(HOST)):
    print "scanning " + HOST[i] + " ...\n"
    try:
        tn = telnetlib.Telnet(HOST[i],23,3)
    except socket.timeout:
        pass

#tn = telnetlib.Telnet(host, port, timeout)
#telnetlib.Telnet(host, port, timeout)

tn.read_until("Welcome to the TeamSpeak 3 ServerQuery interface")

print tn.read_all()

But i seem to get the error from socket saying that it cannot get the address.

C:\Python27\python.exe C:/Users/Khailz/PycharmProjects/Teamspeak-IRC/test.py
scanning 1 ...

Traceback (most recent call last):
  File "C:/Users/KhailzXsniper/PycharmProjects/Teamspeak-IRC/test.py", line 14, in <module>
    tn = telnetlib.Telnet(HOST[i],23,3)
  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 553, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
socket.gaierror: [Errno 11004] getaddrinfo failed

What am I doing wrong

anon582847382

For each character in HOST, you are attempting to resolve that character; this is due to your use of a for loop in combination with indexing HOST. For example in the first iteration you attempt to connect to a host with an I.P. of "1"- that is what produces the gaierror.

To fix it, just don't attempt to connect to a specific index of HOST: get rid of HOST[i] and replace it with HOST alone in the call to telnetlib.Telnet:

tn = telnetlib.Telnet(HOST, 23, 3)

As to what you're trying to do with that loop, however, I'm baffled.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Pycharm python console socket.gaierror

From Dev

socket.gaierror when trying to run emr using python mrjob

From Dev

getaddrinfo failed with socket.gaierror[11001] (python) (mqtt)

From Dev

Installing Python telnetlib module

From Dev

Python telnetlib ending session

From Dev

Python requests multithreading "Max Retries exceeded with url" Caused by <class 'socket.gaierror'>

From Dev

Python socket.py gaierror when trying to use Google Maps API

From Dev

socket.gaierror: Errno 11004 getaddrinfo failed

From Dev

Why am I getting socket.gaierror with httplib?

From Dev

socket.gaierror: [Errno -2] Name or service not known

From Dev

Server connection issue: "socket.gaierror: [Errno 11004] getaddrinfo failed"

From Dev

socket.gaierror: [Errno 8] nodename nor servname provided, or not known

From Dev

Why am I getting socket.gaierror with httplib?

From Dev

Python telnetlib to connect to Scrapy Telnet to read stats

From Dev

Python telnetlib telnet.write() dropping messages

From Dev

Python telnetlib and console connection cisco node

From Dev

telnetlib python read_all() not working(hangs)

From Dev

Python step by step telnetlib output message

From Dev

Python telnetlib seems not imported and returns "no attribute" errors

From Dev

socket.connect() gives socket.gaierror: [Errno 11004] getaddrinfo failed

From Dev

gaierror [Errno 8] when send_mail with Django python and gmail

From Dev

gaierror [Errno 8] when send_mail with Django python and gmail

From Dev

Python telnetlib read_until returns cut off string

From Dev

why telnetlib write function not working in my python code?

From Dev

How do I send telnetlib control + c command in python

From Dev

Python Telnetlib read_until '#' or '>', multiple string determination?

From Dev

Python telnetlib client doesn't appear to be opening telnet connection to server

From Dev

Python telnetlib.expect() dot character '.' not working as expected

From Dev

Python telnetlib read functions return more data than expected

Related Related

  1. 1

    Pycharm python console socket.gaierror

  2. 2

    socket.gaierror when trying to run emr using python mrjob

  3. 3

    getaddrinfo failed with socket.gaierror[11001] (python) (mqtt)

  4. 4

    Installing Python telnetlib module

  5. 5

    Python telnetlib ending session

  6. 6

    Python requests multithreading "Max Retries exceeded with url" Caused by <class 'socket.gaierror'>

  7. 7

    Python socket.py gaierror when trying to use Google Maps API

  8. 8

    socket.gaierror: Errno 11004 getaddrinfo failed

  9. 9

    Why am I getting socket.gaierror with httplib?

  10. 10

    socket.gaierror: [Errno -2] Name or service not known

  11. 11

    Server connection issue: "socket.gaierror: [Errno 11004] getaddrinfo failed"

  12. 12

    socket.gaierror: [Errno 8] nodename nor servname provided, or not known

  13. 13

    Why am I getting socket.gaierror with httplib?

  14. 14

    Python telnetlib to connect to Scrapy Telnet to read stats

  15. 15

    Python telnetlib telnet.write() dropping messages

  16. 16

    Python telnetlib and console connection cisco node

  17. 17

    telnetlib python read_all() not working(hangs)

  18. 18

    Python step by step telnetlib output message

  19. 19

    Python telnetlib seems not imported and returns "no attribute" errors

  20. 20

    socket.connect() gives socket.gaierror: [Errno 11004] getaddrinfo failed

  21. 21

    gaierror [Errno 8] when send_mail with Django python and gmail

  22. 22

    gaierror [Errno 8] when send_mail with Django python and gmail

  23. 23

    Python telnetlib read_until returns cut off string

  24. 24

    why telnetlib write function not working in my python code?

  25. 25

    How do I send telnetlib control + c command in python

  26. 26

    Python Telnetlib read_until '#' or '>', multiple string determination?

  27. 27

    Python telnetlib client doesn't appear to be opening telnet connection to server

  28. 28

    Python telnetlib.expect() dot character '.' not working as expected

  29. 29

    Python telnetlib read functions return more data than expected

HotTag

Archive