0

Hello I am new to python , I am writing a code which generates dns requests

    from socket import error as socket_error
    import threading
    from random import randint
    from time import sleep

    def task(number):
       try :
          HOST = Random_website.random_website().rstrip() # fetches url
          PORT = 80              # The same port as used by the server
          s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

          s.connect((HOST, PORT))
          print(str(number) +":"+HOST +"Connected")
       except socket_error as serr:
         if serr.errno != errno.ECONNREFUSED:
           # Not the error we are looking for, re-raise
            raise serr      

  thread_list = []

  for i in range(1, 100):    
    t = threading.Thread(target=task, args=(i,))
    thread_list.append(t)

  for thread in thread_list:
      thread.start()

Executing above code throws this error, can anyone help me out of this I am pulling out my hair from one day

Thanks in advance

ArK
  • 20,698
  • 67
  • 109
  • 136
abc
  • 1
  • 1
  • 3
  • 1
    Possible duplicate of [What does this socket.gaierror mean?](http://stackoverflow.com/questions/15246088/what-does-this-socket-gaierror-mean) – Aran-Fey Jul 26 '16 at 06:59

2 Answers2

2

Like this:

Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
[GCC 4.8.2] on linux2
Type "copyright", "credits" or "license()" for more information.
>>> import socket
>>> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>>> s.connect(("www.google.com",80))
>>> s.connect(("http://www.google.com",80))

Traceback (most recent call last):
  File "<pyshell#3>", line 1, in <module>
    s.connect(("http://www.google.com",80))
  File "/usr/lib/python2.7/socket.py", line 224, in meth
    return getattr(self._sock,name)(*args)
gaierror: [Errno -2] Name or service not known
>>> 

Socket not a HTTP connection !

Remove HTTP:// tag before sending a request !

EDIT:

>>> import socket
>>> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>>> s.connect(("digan.net",80))
>>> s.connect(("digan.net/hahaha/hihihi/etc",80))

Traceback (most recent call last):
  File "<pyshell#8>", line 1, in <module>
    s.connect(("digan.net/hahaha/hihihi/etc",80))
  File "/usr/lib/python2.7/socket.py", line 224, in meth
    return getattr(self._sock,name)(*args)
gaierror: [Errno -2] Name or service not known
>>> 

Socket can't send request to additional path. Only talk with server !

dsgdfg
  • 1,492
  • 11
  • 18
0

I got the same error message when a web proxy was "on", but the url pointed to a machine in the local network accessible without proxy. Setting the web-proxy (http) to "off" fixed it for me.

Hope this helps, Alex.

Alex.
  • 1