首页 文章

scapy:UDP源端口在发送后更改

提问于
浏览
0

我正在尝试构建一个脚本来测试自行开发的网络协议 . 因此我使用scapy发送请求 . 一切似乎工作正常,但我在代码中指定的UDP源端口似乎在发送过程中发生了变化 . Wireshark中的源端口与我指定的端口不同 . 我也尝试使用tcpdump捕获数据包,但tcpdump也向我显示了错误的端口 . 我在发送之前检查了hexdump,它似乎也是正确的 . 任何想法是什么问题以及如何解决它?

for x in arr:
            cds = TestProtocol(HopCount = 0xe, Length = 0x4, Priority = 0x1, ServiceID = 0x3,
                            ReceiverAddrLen = 0x1, UniqueID1 = 0x1,
                            UniqueID2 = 0x1, SenderAddress = 0x1b4e,
                            PacketType = 0x02c2, data1 = 0x0004,
                            data2 = 0xe6a7, data3 = 0x0)
            ip = IP()
            ip.dst = destAddr
            ip.src = srcAddr
            udp = UDP()

            udp.sport = 1743 #the port which changes
            udp.dport = x
            pack = ip/udp/cds
            send(pack, verbose = True)

1 回答

  • 0

    这意味着你的scapy模块会改变你的端口......这有什么意义呢?!

    我甚至不知道udp通信的“scapy”,也不知道在pythons“socket”-module上使用它的原因是什么?

    对于我通常使用的UDP传输

    import socket
    
    s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
    s.bind(('192.168.66.33', 6022))   #bind local IP and Port
    s.sendto("Calling device", ('192.168.66.48', 6022)) #send string to other IP on same port
    data,addr = s.recvfrom(4096) #buf size 4096 bytes
    print str(data)   #print data received from called device
    

    您也可以将此用于TCP内容

相关问题