scapy:UDP源端口发送后改变

scapy: UDP source port is changed after send

我正在尝试构建一个脚本来测试自行开发的网络协议。因此我使用 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) 

这意味着您的 scapy 模块改变了您的端口...这有什么意义?!

我什至不知道 "scapy" 用于 udp 通信,也不知道为什么要在 pythons "socket"-模块上使用它?

对于 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 内容