{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# TCP Header" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from byteclasses.handlers.network.tcp_hdr import TCPHdr\n", "from byteclasses.print import byteclass_inspect, collection_table, byteclass_info" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "tcp_hdr = TCPHdr()\n", "data = bytearray(\n", " b\"\\x1e\\xc3\\x07\\xd0\\x1f\\xbc\\x16\\xd2\\x00\\x00\\x00\\x00\\x80\\x02\\xfa\\xf0\\x05\\x10\\x00\\x00\"\n", ")\n", "tcp_hdr.attach(memoryview(data))" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
Byteclass Info \n", "┏━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n", "┃ Property ┃ Value ┃\n", "┡━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩\n", "│ type() │ TCPHdr │\n", "│ mro │ TCPHdr -> object │\n", "│ len() │ 20 │\n", "│ str() │ TCPHdr(src_port=UInt16(7875), dst_port=UInt16(2000), seq_number=UInt32(532420306), │\n", "│ │ ack_number=UInt32(0), off_flag=OffFlag(data=b'\\x80\\x02'), window_size=UInt16(64240), │\n", "│ │ checksum=UInt16(1296), urgent_pointer=UInt16(0)) │\n", "│ repr() │ TCPHdr(src_port=UInt16(7875), dst_port=UInt16(2000), seq_number=UInt32(532420306), │\n", "│ │ ack_number=UInt32(0), off_flag=OffFlag(data=b'\\x80\\x02'), window_size=UInt16(64240), │\n", "│ │ checksum=UInt16(1296), urgent_pointer=UInt16(0)) │\n", "│ .data │ bytearray(b'\\x1e\\xc3\\x07\\xd0\\x1f\\xbc\\x16\\xd2\\x00\\x00\\x00\\x00\\x80\\x02\\xfa\\xf0\\x05\\x10\\x00\\x00') │\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[90mTCPHdr \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[91mTCPHdr -> 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[92m20 \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[93mTCPHdr(src_port=UInt16(7875), dst_port=UInt16(2000), seq_number=UInt32(532420306), \u001b[0m\u001b[93m \u001b[0m│\n", "│\u001b[93m \u001b[0m│\u001b[93m \u001b[0m\u001b[93mack_number=UInt32(0), off_flag=OffFlag(data=b'\\x80\\x02'), window_size=UInt16(64240), \u001b[0m\u001b[93m \u001b[0m│\n", "│\u001b[93m \u001b[0m│\u001b[93m \u001b[0m\u001b[93mchecksum=UInt16(1296), urgent_pointer=UInt16(0)) \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[94mTCPHdr(src_port=UInt16(7875), dst_port=UInt16(2000), seq_number=UInt32(532420306), \u001b[0m\u001b[94m \u001b[0m│\n", "│\u001b[94m \u001b[0m│\u001b[94m \u001b[0m\u001b[94mack_number=UInt32(0), off_flag=OffFlag(data=b'\\x80\\x02'), window_size=UInt16(64240), \u001b[0m\u001b[94m \u001b[0m│\n", "│\u001b[94m \u001b[0m│\u001b[94m \u001b[0m\u001b[94mchecksum=UInt16(1296), urgent_pointer=UInt16(0)) \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'\\x1e\\xc3\\x07\\xd0\\x1f\\xbc\\x16\\xd2\\x00\\x00\\x00\\x00\\x80\\x02\\xfa\\xf0\\x05\\x10\\x00\\x00') \u001b[0m\u001b[95m \u001b[0m│\n", "└──────────┴──────────────────────────────────────────────────────────────────────────────────────────────────────┘\n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "byteclass_info(tcp_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 1e c307 d01f bc 16 d200 00 00 0080 02fa f005 1000 00 │\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[90m1e c3\u001b[0m\u001b[91m07 d0\u001b[0m\u001b[92m1f bc 16 d2\u001b[0m\u001b[93m00 00 00 00\u001b[0m\u001b[94m80 02\u001b[0m\u001b[95mfa f0\u001b[0m\u001b[96m05 10\u001b[0m\u001b[90m00 00\u001b[0m │\n", "╰───────────────────────────────────────────────────────────────────────────────────────────────────────╯\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
Legend \n", "┏━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n", "┃ Member ┃ Value ┃\n", "┡━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩\n", "│ src_port │ 7875 │\n", "│ dst_port │ 2000 │\n", "│ seq_number │ 532420306 │\n", "│ ack_number │ 0 │\n", "│ off_flag │ OffFlag(0000000101000000, flags=40) │\n", "│ window_size │ 64240 │\n", "│ checksum │ 1296 │\n", "│ urgent_pointer │ 0 │\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[90m7875 \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[91m2000 \u001b[0m\u001b[91m \u001b[0m│\n", "│\u001b[92m \u001b[0m\u001b[1;92mseq_number \u001b[0m\u001b[92m \u001b[0m│\u001b[92m \u001b[0m\u001b[92m532420306 \u001b[0m\u001b[92m \u001b[0m│\n", "│\u001b[93m \u001b[0m\u001b[1;93mack_number \u001b[0m\u001b[93m \u001b[0m│\u001b[93m \u001b[0m\u001b[93m0 \u001b[0m\u001b[93m \u001b[0m│\n", "│\u001b[94m \u001b[0m\u001b[1;94moff_flag \u001b[0m\u001b[94m \u001b[0m│\u001b[94m \u001b[0m\u001b[94mOffFlag(0000000101000000, flags=40)\u001b[0m\u001b[94m \u001b[0m│\n", "│\u001b[95m \u001b[0m\u001b[1;95mwindow_size \u001b[0m\u001b[95m \u001b[0m│\u001b[95m \u001b[0m\u001b[95m64240 \u001b[0m\u001b[95m \u001b[0m│\n", "│\u001b[96m \u001b[0m\u001b[1;96mchecksum \u001b[0m\u001b[96m \u001b[0m│\u001b[96m \u001b[0m\u001b[96m1296 \u001b[0m\u001b[96m \u001b[0m│\n", "│\u001b[90m \u001b[0m\u001b[1;90murgent_pointer\u001b[0m\u001b[90m \u001b[0m│\u001b[90m \u001b[0m\u001b[90m0 \u001b[0m\u001b[90m \u001b[0m│\n", "└────────────────┴─────────────────────────────────────┘\n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "byteclass_inspect(tcp_hdr)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
TCPHdr \n", "┏━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓\n", "┃ Member ┃ Value ┃ Data ┃\n", "┡━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩\n", "│ src_port │ 7875 │ b'\\x1e\\xc3' │\n", "│ dst_port │ 2000 │ b'\\x07\\xd0' │\n", "│ seq_number │ 532420306 │ b'\\x1f\\xbc\\x16\\xd2' │\n", "│ ack_number │ 0 │ b'\\x00\\x00\\x00\\x00' │\n", "│ off_flag │ OffFlag(0000000101000000, flags=40) │ b'\\x80\\x02' │\n", "│ window_size │ 64240 │ b'\\xfa\\xf0' │\n", "│ checksum │ 1296 │ b'\\x05\\x10' │\n", "│ urgent_pointer │ 0 │ b'\\x00\\x00' │\n", "└────────────────┴─────────────────────────────────────┴─────────────────────┘\n", "\n" ], "text/plain": [ "\u001b[3m TCPHdr \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[90m7875 \u001b[0m\u001b[90m \u001b[0m│\u001b[90m \u001b[0m\u001b[90mb'\\x1e\\xc3' \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[91m2000 \u001b[0m\u001b[91m \u001b[0m│\u001b[91m \u001b[0m\u001b[91mb'\\x07\\xd0' \u001b[0m\u001b[91m \u001b[0m│\n", "│\u001b[92m \u001b[0m\u001b[1;92mseq_number \u001b[0m\u001b[92m \u001b[0m│\u001b[92m \u001b[0m\u001b[92m532420306 \u001b[0m\u001b[92m \u001b[0m│\u001b[92m \u001b[0m\u001b[92mb'\\x1f\\xbc\\x16\\xd2'\u001b[0m\u001b[92m \u001b[0m│\n", "│\u001b[93m \u001b[0m\u001b[1;93mack_number \u001b[0m\u001b[93m \u001b[0m│\u001b[93m \u001b[0m\u001b[93m0 \u001b[0m\u001b[93m \u001b[0m│\u001b[93m \u001b[0m\u001b[93mb'\\x00\\x00\\x00\\x00'\u001b[0m\u001b[93m \u001b[0m│\n", "│\u001b[94m \u001b[0m\u001b[1;94moff_flag \u001b[0m\u001b[94m \u001b[0m│\u001b[94m \u001b[0m\u001b[94mOffFlag(0000000101000000, flags=40)\u001b[0m\u001b[94m \u001b[0m│\u001b[94m \u001b[0m\u001b[94mb'\\x80\\x02' \u001b[0m\u001b[94m \u001b[0m│\n", "│\u001b[95m \u001b[0m\u001b[1;95mwindow_size \u001b[0m\u001b[95m \u001b[0m│\u001b[95m \u001b[0m\u001b[95m64240 \u001b[0m\u001b[95m \u001b[0m│\u001b[95m \u001b[0m\u001b[95mb'\\xfa\\xf0' \u001b[0m\u001b[95m \u001b[0m│\n", "│\u001b[96m \u001b[0m\u001b[1;96mchecksum \u001b[0m\u001b[96m \u001b[0m│\u001b[96m \u001b[0m\u001b[96m1296 \u001b[0m\u001b[96m \u001b[0m│\u001b[96m \u001b[0m\u001b[96mb'\\x05\\x10' \u001b[0m\u001b[96m \u001b[0m│\n", "│\u001b[90m \u001b[0m\u001b[1;90murgent_pointer\u001b[0m\u001b[90m \u001b[0m│\u001b[90m \u001b[0m\u001b[90m0 \u001b[0m\u001b[90m \u001b[0m│\u001b[90m \u001b[0m\u001b[90mb'\\x00\\x00' \u001b[0m\u001b[90m \u001b[0m│\n", "└────────────────┴─────────────────────────────────────┴─────────────────────┘\n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "collection_table(tcp_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 }