socket.gaierror:Errno 11004 getaddrinfo失败

时间:2017-06-10 16:02:02

标签: python python-sockets

我正在尝试使用python创建代理服务器脚本,当我运行它时我有这些恐怖消息请知道我做了什么错误以及如何避免它们(我在网站上播放脚本) 脚本是怎么样的!

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()

这是我的错误消息之一!

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

1 个答案:

答案 0 :(得分:0)

可以替换

吗?
start_new_thread(conn_string, (data, connection))

对齐
start_new_thread(conn_string(data, connection))

尝试运行相同的文件,似乎上面一个是唯一的错误