Python PN-RT数据包格式错误
我试着用这些代码与Ethernet/Profinet协议通信。我发现了这种类型的代码。但是当我带着第1行运行程序时 我没有得到任何错误。我的程序正在运行,但当我观看wireshark端时,我的连接信息显示-2 一, 二, 是的,它知道这是Profinet协议,但为什么格式不正确?我该怎么修理 这是我的python代码:Python PN-RT数据包格式错误,python,python-3.x,wireshark,ethernet,Python,Python 3.x,Wireshark,Ethernet,我试着用这些代码与Ethernet/Profinet协议通信。我发现了这种类型的代码。但是当我带着第1行运行程序时 我没有得到任何错误。我的程序正在运行,但当我观看wireshark端时,我的连接信息显示-2 一, 二, 是的,它知道这是Profinet协议,但为什么格式不正确?我该怎么修理 这是我的python代码: #!/usr/bin/env python import binascii from socket import * from fcntl import ioctl impor
#!/usr/bin/env python
import binascii
from socket import *
from fcntl import ioctl
import struct
import fcntl, struct
value='!6s6sH'
s=socket(AF_PACKET, SOCK_RAW)
s.bind(('enp2s0',1))
class EtherPacket:
def __init__(self, dst='25:36:73:32:74:48', src='c3:82:c5:b8:c2:81', protocol=0x8892):
self.dst = dst # Destination MAC
self.src = src # Source MAC
self.protocol = protocol # Protocol Types
self.raw ="" # Raw Data
self.assemble_eth_feilds()
def assemble_eth_feilds(self):
# Assemble All Feilds Of Ether Packet
self.raw = struct.pack( \
value.encode('ascii'),\
binascii.unhexlify(self.dst.replace(":","")),\
binascii.unhexlify(self.src.replace(":","")),\
self.protocol,\
)
return self.raw
def main():
pkt = EtherPacket()
s.sendto(pkt.raw, ('enp2s0' , 0 ))
if __name__=='__main__':
main()
Wireshark malformed packet PN-RT
#!/usr/bin/env python
import binascii
from socket import *
from fcntl import ioctl
import struct
import fcntl, struct
value='!6s6sH'
s=socket(AF_PACKET, SOCK_RAW)
s.bind(('enp2s0',1))
class EtherPacket:
def __init__(self, dst='25:36:73:32:74:48', src='c3:82:c5:b8:c2:81', protocol=0x8892):
self.dst = dst # Destination MAC
self.src = src # Source MAC
self.protocol = protocol # Protocol Types
self.raw ="" # Raw Data
self.assemble_eth_feilds()
def assemble_eth_feilds(self):
# Assemble All Feilds Of Ether Packet
self.raw = struct.pack( \
value.encode('ascii'),\
binascii.unhexlify(self.dst.replace(":","")),\
binascii.unhexlify(self.src.replace(":","")),\
self.protocol,\
)
return self.raw
def main():
pkt = EtherPacket()
s.sendto(pkt.raw, ('enp2s0' , 0 ))
if __name__=='__main__':
main()