{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# IPv4 Header" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from byteclasses.print import byteclass_inspect, collection_table, byteclass_info\n", "from byteclasses.handlers.network.ipv4_hdr import IPv4Hdr" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "ipv4_hdr = IPv4Hdr()\n", "data = bytearray(b\"\\x45\\x00\\x00\\x34\\x1d\\x12\\x40\\x00\\x80\\x06\\xcb\\xc3\\xc0\\xa8\\xc8\\x87\\xc0\\xa8\\xc8\\x15\")\n", "ipv4_hdr.attach(memoryview(data))" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
Byteclass Info \n", "┏━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n", "┃ Property ┃ Value ┃\n", "┡━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩\n", "│ type() │ IPv4Hdr │\n", "│ mro │ IPv4Hdr -> object │\n", "│ len() │ 20 │\n", "│ str() │ IPv4Hdr(ver_ihl=VerIhl(data=b'E'), dscp_ecn=DscpEcn(data=b'\\x00'), total_length=UInt16(52), │\n", "│ │ identification=UInt16(7442), flags_off=FlagsOff(data=b'@\\x00'), time_to_live=UInt8(128), │\n", "│ │ protocol=UInt8(6), header_checksum=UInt16(52163), src_ip=IPv4Addr(uint8=[UInt8(192), UInt8(168), │\n", "│ │ UInt8(200), UInt8(135)], uint32=UInt32(3232286855)), dst_ip=IPv4Addr(uint8=[UInt8(192), UInt8(168), │\n", "│ │ UInt8(200), UInt8(21)], uint32=UInt32(3232286741))) │\n", "│ repr() │ IPv4Hdr(ver_ihl=VerIhl(data=b'E'), dscp_ecn=DscpEcn(data=b'\\x00'), total_length=UInt16(52), │\n", "│ │ identification=UInt16(7442), flags_off=FlagsOff(data=b'@\\x00'), time_to_live=UInt8(128), │\n", "│ │ protocol=UInt8(6), header_checksum=UInt16(52163), src_ip=IPv4Addr(uint8=[UInt8(192), UInt8(168), │\n", "│ │ UInt8(200), UInt8(135)], uint32=UInt32(3232286855)), dst_ip=IPv4Addr(uint8=[UInt8(192), UInt8(168), │\n", "│ │ UInt8(200), UInt8(21)], uint32=UInt32(3232286741))) │\n", "│ .data │ bytearray(b'E\\x00\\x004\\x1d\\x12@\\x00\\x80\\x06\\xcb\\xc3\\xc0\\xa8\\xc8\\x87\\xc0\\xa8\\xc8\\x15') │\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[90mIPv4Hdr \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[91mIPv4Hdr -> 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[93mIPv4Hdr(ver_ihl=VerIhl(data=b'E'), dscp_ecn=DscpEcn(data=b'\\x00'), total_length=UInt16(52), \u001b[0m\u001b[93m \u001b[0m│\n", "│\u001b[93m \u001b[0m│\u001b[93m \u001b[0m\u001b[93midentification=UInt16(7442), flags_off=FlagsOff(data=b'@\\x00'), time_to_live=UInt8(128), \u001b[0m\u001b[93m \u001b[0m│\n", "│\u001b[93m \u001b[0m│\u001b[93m \u001b[0m\u001b[93mprotocol=UInt8(6), header_checksum=UInt16(52163), src_ip=IPv4Addr(uint8=[UInt8(192), UInt8(168), \u001b[0m\u001b[93m \u001b[0m│\n", "│\u001b[93m \u001b[0m│\u001b[93m \u001b[0m\u001b[93mUInt8(200), UInt8(135)], uint32=UInt32(3232286855)), dst_ip=IPv4Addr(uint8=[UInt8(192), UInt8(168), \u001b[0m\u001b[93m \u001b[0m│\n", "│\u001b[93m \u001b[0m│\u001b[93m \u001b[0m\u001b[93mUInt8(200), UInt8(21)], uint32=UInt32(3232286741))) \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[94mIPv4Hdr(ver_ihl=VerIhl(data=b'E'), dscp_ecn=DscpEcn(data=b'\\x00'), total_length=UInt16(52), \u001b[0m\u001b[94m \u001b[0m│\n", "│\u001b[94m \u001b[0m│\u001b[94m \u001b[0m\u001b[94midentification=UInt16(7442), flags_off=FlagsOff(data=b'@\\x00'), time_to_live=UInt8(128), \u001b[0m\u001b[94m \u001b[0m│\n", "│\u001b[94m \u001b[0m│\u001b[94m \u001b[0m\u001b[94mprotocol=UInt8(6), header_checksum=UInt16(52163), src_ip=IPv4Addr(uint8=[UInt8(192), UInt8(168), \u001b[0m\u001b[94m \u001b[0m│\n", "│\u001b[94m \u001b[0m│\u001b[94m \u001b[0m\u001b[94mUInt8(200), UInt8(135)], uint32=UInt32(3232286855)), dst_ip=IPv4Addr(uint8=[UInt8(192), UInt8(168), \u001b[0m\u001b[94m \u001b[0m│\n", "│\u001b[94m \u001b[0m│\u001b[94m \u001b[0m\u001b[94mUInt8(200), UInt8(21)], uint32=UInt32(3232286741))) \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'E\\x00\\x004\\x1d\\x12@\\x00\\x80\\x06\\xcb\\xc3\\xc0\\xa8\\xc8\\x87\\xc0\\xa8\\xc8\\x15') \u001b[0m\u001b[95m \u001b[0m│\n", "└──────────┴──────────────────────────────────────────────────────────────────────────────────────────────────────┘\n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "byteclass_info(ipv4_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 |45|00|00 34|1d 12|40 00|80|06|cb c3|c0 a8 c8 87|c0 a8 c8 15 │\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[90m45\u001b[0m|\u001b[91m00\u001b[0m|\u001b[92m00 34\u001b[0m|\u001b[93m1d 12\u001b[0m|\u001b[94m40 00\u001b[0m|\u001b[95m80\u001b[0m|\u001b[96m06\u001b[0m|\u001b[90mcb c3\u001b[0m|\u001b[91mc0 a8 c8 87\u001b[0m|\u001b[92mc0 a8 c8 15\u001b[0m │\n", "╰─────────────────────────────────────────────────────────────────────────────────────────────────────────╯\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
Legend \n", "┏━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n", "┃ Member ┃ Value ┃\n", "┡━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩\n", "│ ver_ihl │ VerIhl(10100010, flags={'version': 5, 'ihl': 4}) │\n", "│ dscp_ecn │ DscpEcn(00000000, flags={'dscp': 0, 'ecn': 0}) │\n", "│ total_length │ 52 │\n", "│ identification │ 7442 │\n", "│ flags_off │ FlagsOff(0000001000000000, flags=0) │\n", "│ time_to_live │ 128 │\n", "│ protocol │ 6 │\n", "│ header_checksum │ 52163 │\n", "│ src_ip │ IPv4Addr(uint8=[UInt8(192), UInt8(168), UInt8(200), UInt8(135)], uint32=UInt32(3232286855)) │\n", "│ dst_ip │ IPv4Addr(uint8=[UInt8(192), UInt8(168), UInt8(200), UInt8(21)], uint32=UInt32(3232286741)) │\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;90mver_ihl \u001b[0m\u001b[90m \u001b[0m│\u001b[90m \u001b[0m\u001b[90mVerIhl(10100010, flags={'version': 5, 'ihl': 4}) \u001b[0m\u001b[90m \u001b[0m│\n", "│\u001b[91m \u001b[0m\u001b[1;91mdscp_ecn \u001b[0m\u001b[91m \u001b[0m│\u001b[91m \u001b[0m\u001b[91mDscpEcn(00000000, flags={'dscp': 0, 'ecn': 0}) \u001b[0m\u001b[91m \u001b[0m│\n", "│\u001b[92m \u001b[0m\u001b[1;92mtotal_length \u001b[0m\u001b[92m \u001b[0m│\u001b[92m \u001b[0m\u001b[92m52 \u001b[0m\u001b[92m \u001b[0m│\n", "│\u001b[93m \u001b[0m\u001b[1;93midentification \u001b[0m\u001b[93m \u001b[0m│\u001b[93m \u001b[0m\u001b[93m7442 \u001b[0m\u001b[93m \u001b[0m│\n", "│\u001b[94m \u001b[0m\u001b[1;94mflags_off \u001b[0m\u001b[94m \u001b[0m│\u001b[94m \u001b[0m\u001b[94mFlagsOff(0000001000000000, flags=0) \u001b[0m\u001b[94m \u001b[0m│\n", "│\u001b[95m \u001b[0m\u001b[1;95mtime_to_live \u001b[0m\u001b[95m \u001b[0m│\u001b[95m \u001b[0m\u001b[95m128 \u001b[0m\u001b[95m \u001b[0m│\n", "│\u001b[96m \u001b[0m\u001b[1;96mprotocol \u001b[0m\u001b[96m \u001b[0m│\u001b[96m \u001b[0m\u001b[96m6 \u001b[0m\u001b[96m \u001b[0m│\n", "│\u001b[90m \u001b[0m\u001b[1;90mheader_checksum\u001b[0m\u001b[90m \u001b[0m│\u001b[90m \u001b[0m\u001b[90m52163 \u001b[0m\u001b[90m \u001b[0m│\n", "│\u001b[91m \u001b[0m\u001b[1;91msrc_ip \u001b[0m\u001b[91m \u001b[0m│\u001b[91m \u001b[0m\u001b[91mIPv4Addr(uint8=[UInt8(192), UInt8(168), UInt8(200), UInt8(135)], uint32=UInt32(3232286855))\u001b[0m\u001b[91m \u001b[0m│\n", "│\u001b[92m \u001b[0m\u001b[1;92mdst_ip \u001b[0m\u001b[92m \u001b[0m│\u001b[92m \u001b[0m\u001b[92mIPv4Addr(uint8=[UInt8(192), UInt8(168), UInt8(200), UInt8(21)], uint32=UInt32(3232286741)) \u001b[0m\u001b[92m \u001b[0m│\n", "└─────────────────┴─────────────────────────────────────────────────────────────────────────────────────────────┘\n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "byteclass_inspect(ipv4_hdr)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
IPv4Hdr \n", "┏━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n", "┃ Member ┃ Value ┃ Data ┃\n", "┡━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩\n", "│ ver_ihl │ VerIhl(10100010, flags={'version': 5, 'ihl': 4}) │ b'E' │\n", "│ dscp_ecn │ DscpEcn(00000000, flags={'dscp': 0, 'ecn': 0}) │ b'\\x00' │\n", "│ total_length │ 52 │ b'\\x004' │\n", "│ identification │ 7442 │ b'\\x1d\\x12' │\n", "│ flags_off │ FlagsOff(0000001000000000, flags=0) │ b'@\\x00' │\n", "│ time_to_live │ 128 │ b'\\x80' │\n", "│ protocol │ 6 │ b'\\x06' │\n", "│ header_checksum │ 52163 │ b'\\xcb\\xc3' │\n", "│ src_ip │ IPv4Addr(uint8=[UInt8(192), UInt8(168), UInt8(200), │ bytearray(b'\\xc0\\xa8\\xc8\\x87') │\n", "│ │ UInt8(135)], uint32=UInt32(3232286855)) │ │\n", "│ dst_ip │ IPv4Addr(uint8=[UInt8(192), UInt8(168), UInt8(200), │ bytearray(b'\\xc0\\xa8\\xc8\\x15') │\n", "│ │ UInt8(21)], uint32=UInt32(3232286741)) │ │\n", "└─────────────────┴──────────────────────────────────────────────────────────────┴────────────────────────────────┘\n", "\n" ], "text/plain": [ "\u001b[3m IPv4Hdr \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;90mver_ihl \u001b[0m\u001b[90m \u001b[0m│\u001b[90m \u001b[0m\u001b[90mVerIhl(10100010, flags={'version': 5, 'ihl': 4}) \u001b[0m\u001b[90m \u001b[0m│\u001b[90m \u001b[0m\u001b[90mb'E' \u001b[0m\u001b[90m \u001b[0m│\n", "│\u001b[91m \u001b[0m\u001b[1;91mdscp_ecn \u001b[0m\u001b[91m \u001b[0m│\u001b[91m \u001b[0m\u001b[91mDscpEcn(00000000, flags={'dscp': 0, 'ecn': 0}) \u001b[0m\u001b[91m \u001b[0m│\u001b[91m \u001b[0m\u001b[91mb'\\x00' \u001b[0m\u001b[91m \u001b[0m│\n", "│\u001b[92m \u001b[0m\u001b[1;92mtotal_length \u001b[0m\u001b[92m \u001b[0m│\u001b[92m \u001b[0m\u001b[92m52 \u001b[0m\u001b[92m \u001b[0m│\u001b[92m \u001b[0m\u001b[92mb'\\x004' \u001b[0m\u001b[92m \u001b[0m│\n", "│\u001b[93m \u001b[0m\u001b[1;93midentification \u001b[0m\u001b[93m \u001b[0m│\u001b[93m \u001b[0m\u001b[93m7442 \u001b[0m\u001b[93m \u001b[0m│\u001b[93m \u001b[0m\u001b[93mb'\\x1d\\x12' \u001b[0m\u001b[93m \u001b[0m│\n", "│\u001b[94m \u001b[0m\u001b[1;94mflags_off \u001b[0m\u001b[94m \u001b[0m│\u001b[94m \u001b[0m\u001b[94mFlagsOff(0000001000000000, flags=0) \u001b[0m\u001b[94m \u001b[0m│\u001b[94m \u001b[0m\u001b[94mb'@\\x00' \u001b[0m\u001b[94m \u001b[0m│\n", "│\u001b[95m \u001b[0m\u001b[1;95mtime_to_live \u001b[0m\u001b[95m \u001b[0m│\u001b[95m \u001b[0m\u001b[95m128 \u001b[0m\u001b[95m \u001b[0m│\u001b[95m \u001b[0m\u001b[95mb'\\x80' \u001b[0m\u001b[95m \u001b[0m│\n", "│\u001b[96m \u001b[0m\u001b[1;96mprotocol \u001b[0m\u001b[96m \u001b[0m│\u001b[96m \u001b[0m\u001b[96m6 \u001b[0m\u001b[96m \u001b[0m│\u001b[96m \u001b[0m\u001b[96mb'\\x06' \u001b[0m\u001b[96m \u001b[0m│\n", "│\u001b[90m \u001b[0m\u001b[1;90mheader_checksum\u001b[0m\u001b[90m \u001b[0m│\u001b[90m \u001b[0m\u001b[90m52163 \u001b[0m\u001b[90m \u001b[0m│\u001b[90m \u001b[0m\u001b[90mb'\\xcb\\xc3' \u001b[0m\u001b[90m \u001b[0m│\n", "│\u001b[91m \u001b[0m\u001b[1;91msrc_ip \u001b[0m\u001b[91m \u001b[0m│\u001b[91m \u001b[0m\u001b[91mIPv4Addr(uint8=[UInt8(192), UInt8(168), UInt8(200), \u001b[0m\u001b[91m \u001b[0m│\u001b[91m \u001b[0m\u001b[91mbytearray(b'\\xc0\\xa8\\xc8\\x87')\u001b[0m\u001b[91m \u001b[0m│\n", "│\u001b[91m \u001b[0m│\u001b[91m \u001b[0m\u001b[91mUInt8(135)], uint32=UInt32(3232286855)) \u001b[0m\u001b[91m \u001b[0m│\u001b[91m \u001b[0m│\n", "│\u001b[92m \u001b[0m\u001b[1;92mdst_ip \u001b[0m\u001b[92m \u001b[0m│\u001b[92m \u001b[0m\u001b[92mIPv4Addr(uint8=[UInt8(192), UInt8(168), UInt8(200), \u001b[0m\u001b[92m \u001b[0m│\u001b[92m \u001b[0m\u001b[92mbytearray(b'\\xc0\\xa8\\xc8\\x15')\u001b[0m\u001b[92m \u001b[0m│\n", "│\u001b[92m \u001b[0m│\u001b[92m \u001b[0m\u001b[92mUInt8(21)], uint32=UInt32(3232286741)) \u001b[0m\u001b[92m \u001b[0m│\u001b[92m \u001b[0m│\n", "└─────────────────┴──────────────────────────────────────────────────────────────┴────────────────────────────────┘\n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "collection_table(ipv4_hdr)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0xc0a80101 0x7f000001\n", "bytearray(b'\\xc0\\xa8\\x01\\x01') bytearray(b'\\x7f\\x00\\x00\\x01')\n" ] } ], "source": [ "ipv4_hdr.src_ip.uint8[:] = [192,168,1,1]\n", "ipv4_hdr.dst_ip.uint8[:] = [127, 0, 0, 1]\n", "print(hex(ipv4_hdr.src_ip.uint32), hex(ipv4_hdr.dst_ip.uint32))\n", "print(ipv4_hdr.src_ip.data, ipv4_hdr.dst_ip.data)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "bytearray(b'\\xde\\xad\\xbe\\xef') bytearray(b'\\xca\\xfe\\xba\\xbe')\n", "bytearray(b'E\\x00\\x004\\x1d\\x12@\\x00\\x80\\x06\\xcb\\xc3\\xde\\xad\\xbe\\xef\\xca\\xfe\\xba\\xbe')\n" ] } ], "source": [ "ipv4_hdr.src_ip.uint32 = 0xdeadbeef\n", "ipv4_hdr.dst_ip.uint32 = 0xcafebabe\n", "print(ipv4_hdr.src_ip.data, ipv4_hdr.dst_ip.data)\n", "print(ipv4_hdr.data)" ] } ], "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 }