python - 与服务器 Python 的多套接字连接

标签 python sockets

我在 python 套接字中收到此错误。我的目标是创建一个缓慢的 lorris 攻击,但我在一个程序中与路由器建立多个连接时遇到问题

我想获取列表中要调用的套接字数量

import socket
import time
import os
import random

socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

user_agents = [
    "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36",
    "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36",
    "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/602.1.50 (KHTML, like Gecko) Version/10.0 Safari/602.1.50",
    "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:49.0) Gecko/20100101 Firefox/49.0",
    "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36",
    "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36",
    "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36",
    "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/602.2.14 (KHTML, like Gecko) Version/10.0.1 Safari/602.2.14",
    "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12) AppleWebKit/602.1.50 (KHTML, like Gecko) Version/10.0 Safari/602.1.50",
    "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36 Edge/14.14393"
    "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36",
    "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36",
    "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36",
    "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36",
    "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:49.0) Gecko/20100101 Firefox/49.0",
    "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36",
    "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36",
    "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36",
    "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36",
    "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:49.0) Gecko/20100101 Firefox/49.0",
    "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko",
    "Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.0",
    "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36",
    "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36",
    "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:49.0) Gecko/20100101 Firefox/49.0",
]

def clear():
    os.system("cls")

print("Starting...")
print("press enter to start")
agreement = input("")

port = 445
port_s = str(port)
socket.settimeout(4)


list_of_sockets = []

import socket
servers = [] #add servers here
if agreement == "":
    clear()
    print("")


    print("welcome...")
    target = input("ip target>>>")
    print("defult port is " + port_s)
    print("-" * 10 + " START " + "-" * 10)
    print("")
    def connect_to():
        int_nob = int(200)#num of bots
        for x in range(0, int_nob):
            print(int(int_nob))
            int_nob -= 1
            int_nob = socket.connect((target, port))
            int_nob.send("User-Agent: {}\r\n".format(random.choice(user_agents)).encode("utf-8"))
            client = new Client()
            if int_nob == 0:
                print(list_of_sockets)
                print("resending sockets of " + int_nob)
    while True:
        connect_to()
    else:
        print("breaking...")
        exit()

错误

Traceback (most recent call last):
  File "C:\Users\townte23\Desktop\slow lorris,.py", line 78, in <module>
    connect_to()
  File "C:\Users\townte23\Desktop\slow lorris,.py", line 71, in connect_to
    a = socket.connect((target, port))
OSError: [WinError 10056] A connect request was made on an already connected socket

我确实蚕食了别人的代码,但大部分都是我的 https://github.com/gkbrk/slowloris/blob/master/slowloris.py

我确实发现了类似的问题,但这是服务器问题,所以我不确定如何解决此错误

编辑:找到问题和解决方案

int_nob = int(200)
for
     int_nob = socket.connect(())
     int_nob.send(bytes("thing"))
     int_nob -= 1

最佳答案

socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
...
    def connect_to():
        ...
        for x in range(0, int_nob):
            ...
            a = socket.connect((target, port))
            ...
    while True:
        connect_to()

您不能使用同一个套接字进行多个连接,但必须为每个新连接创建一个新套接字。除此之外,您将套接字简单地称为 socket 是非常令人困惑的,因为这在名称上与您导入的模块 socket 冲突。

关于python - 与服务器 Python 的多套接字连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55193428/

相关文章:

python - 将两列设置为 pandas 数据框中的索引以进行时间序列分析

python - 值的微小差异取决于查询区域的大小

java - 动态 IP 地址套接字

sql-server - Node.js sequelize-auto 无法连接到 mssql 数据库套接字挂断

networking - 如何获取套接字的非 ACK-ed TCP 数据量?

python - Matplotlib:在同一轴位置显示次要刻度和主要刻度

python - 类型错误 : unsupported operand type(s) for -: 'str' and 'str' in python 3. x python

java - 处理tcp java socket项目中的异常

python - 根据连续值之间的差异将列表拆分为子列表

c++ - 如何使用libcurl在本地IP上获取HTML?