-5

i am trying to create a proxy server script with python when i run it i have this arror messages please can i know what are the mistakes i've done and how to avoid them (i sow the script on a site) how the script looks like !

import socket
from thread import *
import sys
host = ""
port = 91
def start():

    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.bind((host, port))
    s.listen(5)
    print "[+] listening ..."
    while True:
        try:
            connection, address = s.accept()
            data = connection.recv(1024)
            start_new_thread(conn_string, (data, connection))


        except KeyboardInterrupt:
            print "\n\nclosing !"

def conn_string(data, con):
    webserver = ""
    portserver = 0
    f_li = data.split('\n')[0]
    lien = f_li.split(' ')[1]



    http_pos = lien.find("://")

    if http_pos == -1:
        url = lien
    else:
        url = lien[(http_pos+3):]

    port_pos = url.find(':')
    if port_pos == -1:

        portserver = 80

    else:
        portserver = url[(port_pos+1):]


    s_pos = url.find('/')
    if s_pos == -1:
        webserver = url
    else:
        webserver = url[:(s_pos)]

    proxy_server(webserver, portserver, data, con)

def proxy_server(webserver, portserver, data, con):
    print webserver
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect((webserver, int(portserver)))
    s.send(data)
    while True:
        red = s.recv(8192)
        if len(red) > 0:
            con.send(red)


start()

this is one of the error messages that i have !

Unhandled exception in thread started by <function conn_string at 0x0248CEF0>
Traceback (most recent call last):
  File "C:\Users\none2\Desktop\Nouveau dossier\Target.py", line 52, in conn_stri
ng
    proxy_server(webserver, portserver, data, con)
  File "C:\Users\none2\Desktop\Nouveau dossier\Target.py", line 57, in proxy_ser
ver
    s.connect((webserver, int(portserver)))
  File "C:\Python27\lib\socket.py", line 228, in meth
    return getattr(self._sock,name)(*args)
socket.gaierror: [Errno 11004] getaddrinfo failed
amine
  • 3
  • 3
  • *"i have this arror messages"* - what error messages? If you want us to help you need to actually explain what's wrong. Also most of the time just putting the error into a search engine will show you how to fix it – UnholySheep Jun 10 '17 at 16:05
  • thanks sir but i already search for the error i find a lot of solutions but not for this script – amine Jun 10 '17 at 16:09
  • Add the traceback to your question as text. Links to pictures of text are useless. – thebjorn Jun 10 '17 at 16:10
  • ... and questions of the form "why doesn't this code work" are not a good fit for Stack Overflow. – thebjorn Jun 10 '17 at 16:12
  • ok sir i'll try – amine Jun 10 '17 at 16:12
  • shold i remove words like why doesn't this code work from question ? – amine Jun 10 '17 at 16:14
  • Copy paste the error, that's preferred, otherwise mention which file, which line is causing the problem. Also, if some library file throws an error because your code is wrong making, your question title with that error line is more appropriate. – Bishwas Mishra Jun 10 '17 at 16:17
  • ok sir thans for your help – amine Jun 10 '17 at 16:18
  • Smilar problem: https://stackoverflow.com/questions/6180720/how-to-fix-socket-gaierror-11004-getaddrinfo-failed-error-in-gae – Bishwas Mishra Jun 10 '17 at 16:20

1 Answers1

0

can you replace

start_new_thread(conn_string, (data, connection))

line with

start_new_thread(conn_string(data, connection))

tried running the same file, it seems above one is the only error

pramod
  • 1,453
  • 1
  • 14
  • 16