{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# UDP Header" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from byteclasses.handlers.network.udp_hdr import UDPHdr\n", "from byteclasses.print import byteclass_inspect, collection_table, byteclass_info" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "udp_hdr = UDPHdr()\n", "data = bytearray(b\"\\x80\\x00\\x04\\xd2\\x00\\x00\\x38\\x45\")\n", "udp_hdr.attach(memoryview(data))" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
Byteclass Info \n", "┏━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n", "┃ Property ┃ Value ┃\n", "┡━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩\n", "│ type() │ UDPHdr │\n", "│ mro │ UDPHdr -> object │\n", "│ len() │ 8 │\n", "│ str() │ UDPHdr(src_port=UInt16(32768), dst_port=UInt16(1234), length=UInt16(0), checksum=UInt16(14405)) │\n", "│ repr() │ UDPHdr(src_port=UInt16(32768), dst_port=UInt16(1234), length=UInt16(0), checksum=UInt16(14405)) │\n", "│ .data │ bytearray(b'\\x80\\x00\\x04\\xd2\\x00\\x008E') │\n", "└──────────┴─────────────────────────────────────────────────────────────────────────────────────────────────┘\n", "\n" ], "text/plain": [ "\u001b[3m Byteclass Info \u001b[0m\n", "┏━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n", "┃\u001b[1m \u001b[0m\u001b[1mProperty\u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mValue \u001b[0m\u001b[1m \u001b[0m┃\n", "┡━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩\n", "│\u001b[90m \u001b[0m\u001b[1;90mtype() \u001b[0m\u001b[90m \u001b[0m│\u001b[90m \u001b[0m\u001b[90mUDPHdr \u001b[0m\u001b[90m \u001b[0m│\n", "│\u001b[91m \u001b[0m\u001b[1;91mmro \u001b[0m\u001b[91m \u001b[0m│\u001b[91m \u001b[0m\u001b[91mUDPHdr -> object \u001b[0m\u001b[91m \u001b[0m│\n", "│\u001b[92m \u001b[0m\u001b[1;92mlen() \u001b[0m\u001b[92m \u001b[0m│\u001b[92m \u001b[0m\u001b[92m8 \u001b[0m\u001b[92m \u001b[0m│\n", "│\u001b[93m \u001b[0m\u001b[1;93mstr() \u001b[0m\u001b[93m \u001b[0m│\u001b[93m \u001b[0m\u001b[93mUDPHdr(src_port=UInt16(32768), dst_port=UInt16(1234), length=UInt16(0), checksum=UInt16(14405))\u001b[0m\u001b[93m \u001b[0m│\n", "│\u001b[94m \u001b[0m\u001b[1;94mrepr() \u001b[0m\u001b[94m \u001b[0m│\u001b[94m \u001b[0m\u001b[94mUDPHdr(src_port=UInt16(32768), dst_port=UInt16(1234), length=UInt16(0), checksum=UInt16(14405))\u001b[0m\u001b[94m \u001b[0m│\n", "│\u001b[95m \u001b[0m\u001b[1;95m.data \u001b[0m\u001b[95m \u001b[0m│\u001b[95m \u001b[0m\u001b[95mbytearray(b'\\x80\\x00\\x04\\xd2\\x00\\x008E') \u001b[0m\u001b[95m \u001b[0m│\n", "└──────────┴─────────────────────────────────────────────────────────────────────────────────────────────────┘\n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "byteclass_info(udp_hdr)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
╭───────────────────────────────────────── Byteclass Inspect ──────────────────────────────────────────╮\n", "│ 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 │\n", "│ --------------------------------------------------------------------------------------------------- │\n", "│ 0x0 80 0004 d200 0038 45 │\n", "╰──────────────────────────────────────────────────────────────────────────────────────────────────────╯\n", "\n" ], "text/plain": [ "╭───────────────────────────────────────── Byteclass Inspect ──────────────────────────────────────────╮\n", "│ 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 │\n", "│ --------------------------------------------------------------------------------------------------- │\n", "│ 0x0 \u001b[90m80 00\u001b[0m\u001b[91m04 d2\u001b[0m\u001b[92m00 00\u001b[0m\u001b[93m38 45\u001b[0m │\n", "╰──────────────────────────────────────────────────────────────────────────────────────────────────────╯\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
Legend \n", "┏━━━━━━━━━━┳━━━━━━━┓\n", "┃ Member ┃ Value ┃\n", "┡━━━━━━━━━━╇━━━━━━━┩\n", "│ src_port │ 32768 │\n", "│ dst_port │ 1234 │\n", "│ length │ 0 │\n", "│ checksum │ 14405 │\n", "└──────────┴───────┘\n", "\n" ], "text/plain": [ "\u001b[3m Legend \u001b[0m\n", "┏━━━━━━━━━━┳━━━━━━━┓\n", "┃\u001b[1m \u001b[0m\u001b[1mMember \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mValue\u001b[0m\u001b[1m \u001b[0m┃\n", "┡━━━━━━━━━━╇━━━━━━━┩\n", "│\u001b[90m \u001b[0m\u001b[1;90msrc_port\u001b[0m\u001b[90m \u001b[0m│\u001b[90m \u001b[0m\u001b[90m32768\u001b[0m\u001b[90m \u001b[0m│\n", "│\u001b[91m \u001b[0m\u001b[1;91mdst_port\u001b[0m\u001b[91m \u001b[0m│\u001b[91m \u001b[0m\u001b[91m1234 \u001b[0m\u001b[91m \u001b[0m│\n", "│\u001b[92m \u001b[0m\u001b[1;92mlength \u001b[0m\u001b[92m \u001b[0m│\u001b[92m \u001b[0m\u001b[92m0 \u001b[0m\u001b[92m \u001b[0m│\n", "│\u001b[93m \u001b[0m\u001b[1;93mchecksum\u001b[0m\u001b[93m \u001b[0m│\u001b[93m \u001b[0m\u001b[93m14405\u001b[0m\u001b[93m \u001b[0m│\n", "└──────────┴───────┘\n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "byteclass_inspect(udp_hdr)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
UDPHdr \n", "┏━━━━━━━━━━┳━━━━━━━┳━━━━━━━━━━━━━┓\n", "┃ Member ┃ Value ┃ Data ┃\n", "┡━━━━━━━━━━╇━━━━━━━╇━━━━━━━━━━━━━┩\n", "│ src_port │ 32768 │ b'\\x80\\x00' │\n", "│ dst_port │ 1234 │ b'\\x04\\xd2' │\n", "│ length │ 0 │ b'\\x00\\x00' │\n", "│ checksum │ 14405 │ b'8E' │\n", "└──────────┴───────┴─────────────┘\n", "\n" ], "text/plain": [ "\u001b[3m UDPHdr \u001b[0m\n", "┏━━━━━━━━━━┳━━━━━━━┳━━━━━━━━━━━━━┓\n", "┃\u001b[1m \u001b[0m\u001b[1mMember \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mValue\u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mData \u001b[0m\u001b[1m \u001b[0m┃\n", "┡━━━━━━━━━━╇━━━━━━━╇━━━━━━━━━━━━━┩\n", "│\u001b[90m \u001b[0m\u001b[1;90msrc_port\u001b[0m\u001b[90m \u001b[0m│\u001b[90m \u001b[0m\u001b[90m32768\u001b[0m\u001b[90m \u001b[0m│\u001b[90m \u001b[0m\u001b[90mb'\\x80\\x00'\u001b[0m\u001b[90m \u001b[0m│\n", "│\u001b[91m \u001b[0m\u001b[1;91mdst_port\u001b[0m\u001b[91m \u001b[0m│\u001b[91m \u001b[0m\u001b[91m1234 \u001b[0m\u001b[91m \u001b[0m│\u001b[91m \u001b[0m\u001b[91mb'\\x04\\xd2'\u001b[0m\u001b[91m \u001b[0m│\n", "│\u001b[92m \u001b[0m\u001b[1;92mlength \u001b[0m\u001b[92m \u001b[0m│\u001b[92m \u001b[0m\u001b[92m0 \u001b[0m\u001b[92m \u001b[0m│\u001b[92m \u001b[0m\u001b[92mb'\\x00\\x00'\u001b[0m\u001b[92m \u001b[0m│\n", "│\u001b[93m \u001b[0m\u001b[1;93mchecksum\u001b[0m\u001b[93m \u001b[0m│\u001b[93m \u001b[0m\u001b[93m14405\u001b[0m\u001b[93m \u001b[0m│\u001b[93m \u001b[0m\u001b[93mb'8E' \u001b[0m\u001b[93m \u001b[0m│\n", "└──────────┴───────┴─────────────┘\n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "collection_table(udp_hdr)" ] } ], "metadata": { "kernelspec": { "display_name": ".venv", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.9" } }, "nbformat": 4, "nbformat_minor": 2 }