eth.py 313 B

1234567891011
  1. import struct
  2. import socket
  3. def ethernet_unpack(data):
  4. dest_mac, src_mac, eth_proto = struct.unpack('! 6s 6s H', data[:14])
  5. return getmac(dest_mac), getmac(src_mac), socket.htons(eth_proto), data[14:]
  6. def getmac(mac_bytes):
  7. mac = map ('{:02x}'.format, mac_bytes)
  8. return (':'.join(mac)).upper()