PN-RT数据包格式错误

时间:2018-10-23 10:18:46

标签: python python-3.x wireshark ethernet

我尝试使用该代码与以太网/ Profinet协议通信。我发现了这种类型的代码。但是当我用第1行运行程序时 而且我没有得到任何错误。我的程序正在运行,但是当我看着接线端时,我的连接信息说为-2

1

sudo python3 discovery.py

2

Wireshark malformed packet PN-RT

是的,它知道这是Profinet协议,但是为什么格式不正确?我该如何解决?

那是我的python代码:

#!/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()

0 个答案:

没有答案