Ethernet Header and Frame

[1]:
from byteclasses.handlers.network.eth_hdr import EthHdr
from byteclasses.handlers.network.eth_frame import EthFrame
from byteclasses.print import byteclass_inspect, collection_table, byteclass_info
from rich.console import Console
from rich.table import Table
[2]:
eth_hdr = EthHdr()
data = bytearray(b"\x00\x0c\x29\xb4\x90\x14\xec\xf4\xbb\x96\x12\x0e\x08\x00")
eth_hdr.attach(memoryview(data))
[3]:
byteclass_info(eth_hdr)
                                                  Byteclass Info                                                   
┏━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Property  Value                                                                                                ┃
┡━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ type()    EthHdr                                                                                               │
│ mro       EthHdr -> object                                                                                     │
│ len()     14                                                                                                   │
│ str()     EthHdr(dst_mac=[UInt8(0), UInt8(12), UInt8(41), UInt8(180), UInt8(144), UInt8(20)],                  │
│           src_mac=[UInt8(236), UInt8(244), UInt8(187), UInt8(150), UInt8(18), UInt8(14)],                      │
│           ether_type=UInt16(2048))                                                                             │
│ repr()    EthHdr(dst_mac=[UInt8(0), UInt8(12), UInt8(41), UInt8(180), UInt8(144), UInt8(20)],                  │
│           src_mac=[UInt8(236), UInt8(244), UInt8(187), UInt8(150), UInt8(18), UInt8(14)],                      │
│           ether_type=UInt16(2048))                                                                             │
│ .data     bytearray(b'\x00\x0c)\xb4\x90\x14\xec\xf4\xbb\x96\x12\x0e\x08\x00')                                  │
└──────────┴──────────────────────────────────────────────────────────────────────────────────────────────────────┘
[4]:
byteclass_inspect(eth_hdr)
╭───────────────────────────────────────── Byteclass Inspect ──────────────────────────────────────────╮
│     00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f  │
│ ---------------------------------------------------------------------------------------------------  │
│ 0x0 00 0c 29 b4 90 14ec f4 bb 96 12 0e08 00                                                          │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────╯
                                        Legend                                         
┏━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Member      Value                                                                  ┃
┡━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ dst_mac     [UInt8(0), UInt8(12), UInt8(41), UInt8(180), UInt8(144), UInt8(20)]    │
│ src_mac     [UInt8(236), UInt8(244), UInt8(187), UInt8(150), UInt8(18), UInt8(14)] │
│ ether_type  2048                                                                   │
└────────────┴────────────────────────────────────────────────────────────────────────┘
[5]:
collection_table(eth_hdr)
                                                      EthHdr                                                       
┏━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Member      Value                                                                 Data                        ┃
┡━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ dst_mac     [UInt8(0), UInt8(12), UInt8(41), UInt8(180), UInt8(144), UInt8(20)]   b'\x00\x0c)\xb4\x90\x14'    │
│ src_mac     [UInt8(236), UInt8(244), UInt8(187), UInt8(150), UInt8(18),           b'\xec\xf4\xbb\x96\x12\x0e' │
│             UInt8(14)]                                                                                        │
│ ether_type  2048                                                                  b'\x08\x00'                 │
└────────────┴──────────────────────────────────────────────────────────────────────┴─────────────────────────────┘
[6]:
data = b"\xf0\x9f\xc2\xdf\x16\x1f\x00\x0c\x29\xfa\xa3\x37\x08\x00\x45\x00\x00\x54\x39\x03\x40\x00\x40\x01\x68\xd8\xc0\xa8\xc8\x15\x08\x08\x08\x08\x08\x00\xda\xda\x20\x62\x00\x01\x52\xf2\xa8\x62\x00\x00\x00\x00\x3d\x9a\x05\x00\x00\x00\x00\x00\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x32\x33\x34\x35\x36\x37"
ef = EthFrame(data=data)
[7]:
table = Table(title="Ethernet Frame")

table.add_column("Name")
table.add_column("Value")

table.add_row("len(ef)", str(len(ef)))
table.add_row("str(ef)", str(ef))
table.add_row("repr(ef)", repr(ef))
table.add_row("ef.data", str(ef.data))
table.add_row("ef.src_mac", str(ef.src_mac))
table.add_row("ef.dst_mac", str(ef.dst_mac))
table.add_row("ef.type", str(ef.type))

console = Console()
console.print(table)
                                      Ethernet Frame                                      
┏━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Name        Value                                                                     ┃
┡━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ len(ef)    │ 98                                                                        │
│ str(ef)    │ EthFrame(src_mac=00:0c:29:fa:a3:37, dst_mac=f0:9f:c2:df:16:1f, type=IPV4) │
│ repr(ef)   │ EthFrame(data=<memory at 0x12066bc40>)                                    │
│ ef.data    │ <memory at 0x12066bc40>                                                   │
│ ef.src_mac │ 00:0c:29:fa:a3:37                                                         │
│ ef.dst_mac │ f0:9f:c2:df:16:1f                                                         │
│ ef.type    │ IPV4                                                                      │
└────────────┴───────────────────────────────────────────────────────────────────────────┘