Skip to main content

I2NeT (Images to Network Traffic), extract and reconstruct data from RGB-encoded PNG images into CSV format. Suitable for CNN-based anomaly detection.

Project description

I2NeT (Image to Network) ๐Ÿ–ผ๏ธ โžก๏ธ ๐Ÿ“Š

I2NeT is the reverse companion to NeT2I. It decodes RGB images created from network traffic data back into structured tabular form. This enhanced version supports both IPv4 and IPv6 network data with intelligent adaptive decoding.

๐Ÿงฉ Important: I2NeT decodes only the format output by NeT2I. Images from other tools will not decode correctly.

โœจ Features

  • ๐Ÿ” Bi-directional Processing: Reverses RGB images generated by NeT2I into CSV-format network traffic data
  • ๐ŸŒ Dual IP Support: Handles both IPv4 and IPv6 network addresses seamlessly
  • ๐Ÿง  Adaptive Decoding: Automatically detects data structure and adjusts decoding strategy
  • ๐ŸŽฏ Smart Type Detection: Uses filename prefixes (ipv4_, ipv6_) for automatic protocol detection
  • ๐Ÿ’ก Comprehensive Data Types:
    • IPv4 addresses (4 octets from 8 RGB pixels)
    • IPv6 addresses (16 bytes from 6 RGB pixels)
    • MAC addresses (6 bytes from 4 RGB pixels)
    • Integers and floats (IEEE 754 from 2 RGB pixels)
    • Strings (via consistent hash representations)
  • ๐Ÿ”ง Flexible Configuration: Supports separate type definitions for IPv4 and IPv6
  • ๐Ÿ“Š Batch Processing: Handles multiple image sets with progress tracking
  • ๐Ÿ›ก๏ธ Error Resilience: Graceful handling of incomplete or corrupted data

๐Ÿ“‹ Requirements

  • Python 3.9+
  • Dependencies:
    • Pillow
    • NumPy
    • Standard library modules (struct, json, csv, glob, ipaddress)

๐Ÿš€ Installation

# Install required dependencies
pip install pillow numpy

# Clone the repository
git clone https://github.com/omeshF/I2NeT.git
cd I2NeT

๐Ÿ“ Directory Structure

Organize your PNG images with proper naming conventions:

data/
โ”œโ”€โ”€ ipv4_0.png          # IPv4 data images
โ”œโ”€โ”€ ipv4_1.png
โ”œโ”€โ”€ ipv4_2.png
โ”œโ”€โ”€ ipv6_0.png          # IPv6 data images  
โ”œโ”€โ”€ ipv6_1.png
โ”œโ”€โ”€ ipv6_2.png
โ”œโ”€โ”€ data_types.json     # IPv4 type definitions (optional)
โ””โ”€โ”€ data_types_ipv6.json # IPv6 type definitions (optional)

๐ŸŽฏ Usage

Basic Usage

import I2NeT.decoder as decoder

# Decode all images in directory
results = decoder.decode(
    data_directory='data',
    output_csv='decoded_network_data.csv'
)

print(f"โœ… Processed {results['total_images_processed']} images")
print(f"๐Ÿ“Š Generated {results['total_rows']} data rows")

Advanced Configuration

import I2NeT.decoder as decoder

# Custom configuration with separate type files
results = decoder.decode(
    data_directory='network_images',
    output_csv='reconstructed_data.csv',
    types_file_ipv4='ipv4_schema.json',
    types_file_ipv6='ipv6_schema.json',
    verbose=True
)

# Access detailed breakdown
print(f"IPv4 rows: {results['ipv4_rows']}")
print(f"IPv6 rows: {results['ipv6_rows']}")
print(f"Success: {results['success']}")

Single Image Decoding

import I2NeT.decoder as decoder

# Decode individual image
values = decoder.decode_single(
    image_path='data/ipv6_0.png',
    is_ipv6=True
)
print(f"Decoded values: {values}")

# Auto-detect from filename
values = decoder.decode_single('data/ipv4_5.png')  # Auto-detects IPv4

Using the Enhanced Decoder Class

from I2NeT.decoder import EnhancedI2NeT_Decoder

# Create decoder instance
decoder = EnhancedI2NeT_Decoder(
    types_file_ipv4='data_types.json',
    types_file_ipv6='data_types_ipv6.json'
)

# Process different datasets
results = decoder.load_data('network_captures', verbose=True)

# Decode specific image
reconstructed = decoder.decode_single_image('capture_001.png', is_ipv6=False)

๐Ÿ” Decoding Logic

Data Type Storage Method Decoding Process
Float/Integer 2 RGB pixels (6 bytes) IEEE 754 float extraction
IPv4 Address 8 RGB pixels (4 octets ร— 2 pixels) 4 floats โ†’ 4 octets โ†’ dotted decimal
IPv6 Address 6 RGB pixels (18 bytes) 16 bytes โ†’ IPv6 address object
MAC Address 4 RGB pixels (2 chunks ร— 2 pixels) 2 floats โ†’ hex chunks โ†’ colon notation
String 2 RGB pixels Hash value โ†’ string representation

Adaptive Decoding Features

  • Truncation Handling: Gracefully processes incomplete data by treating remaining pixels as floats
  • Type Detection: Automatically determines data structure from available RGB pixel count
  • Fallback Strategy: Uses generic float decoding when type information is unavailable
  • Mixed Protocol Support: Handles datasets containing both IPv4 and IPv6 addresses

๐Ÿ“Š Output Files

File Description
decoded_network_data.csv Final merged output with all decoded data
data_types.json IPv4 type schema (optional)
data_types_ipv6.json IPv6 type schema (optional)

๐Ÿ› ๏ธ Type Definition Files

Create JSON files to guide the decoding process:

data_types.json (IPv4):

{
  "original_types": ["IPv4 Address", "MAC Address", "Integer", "Float"],
  "final_types": ["IPv4 Address", "IPv4 Address", "IPv4 Address", "IPv4 Address", "MAC Address", "MAC Address", "Integer", "Float"]
}

data_types_ipv6.json (IPv6):

{
  "original_types": ["IPv6 Address", "MAC Address", "Float"],
  "final_types": ["IPv6 Address", "MAC Address", "MAC Address", "Float"]
}

โšก Performance & Compatibility

  • Multi-format Support: PNG, JPG, JPEG, BMP, TIFF
  • Batch Processing: Progress tracking for large datasets
  • Memory Efficient: Processes images sequentially to minimize memory usage
  • Error Recovery: Continues processing even if individual images fail

๐Ÿšจ Important Notes

  1. NeT2I Compatibility: Only works with images generated by NeT2I
  2. Filename Conventions: Use ipv4_ and ipv6_ prefixes for automatic protocol detection
  3. Type Files: Optional but recommended for accurate IP and MAC address reconstruction
  4. Image Order: Files are sorted numerically when possible, alphabetically otherwise

๐ŸŽฏ Use Cases

This enhanced I2NeT decoder is ideal for:

  • Network Security Analysis: Reconstructing network traffic from image-encoded datasets
  • Machine Learning Workflows: Converting CNN-processed network images back to structured data
  • Data Integrity Verification: Validating image-encoded datasets before training
  • Mixed Protocol Datasets: Handling modern networks with both IPv4 and IPv6 traffic
  • Forensic Analysis: Recovering network data from visual representations

๐Ÿ“š API Reference

Main Functions

  • decode(data_directory, output_csv, ...) - Main decoding function
  • decode_single(image_path, ...) - Single image decoder
  • load_data_with_ipv4_ipv6_support(...) - Enhanced loader with dual IP support
  • get_decoder(...) - Factory function for decoder instances

Classes

  • EnhancedI2NeT_Decoder - Main decoder class with advanced features

๐Ÿ“– Citation

If you use I2NeT or NeT2I in your research, please cite:

@inproceedings{fernando2023new,
  title={New algorithms for the detection of malicious traffic in 5g-mec},
  author={Fernando, Omesh A and Xiao, Hannan and Spring, Joseph},
  booktitle={2023 IEEE Wireless Communications and Networking Conference (WCNC)},
  pages={1--6},
  year={2023},
  organization={IEEE}
}

๐Ÿ‘ฅ Authors

  • Omesh Fernando

๐Ÿ“„ License

This project is licensed under the MIT License.


๐Ÿ”— Related Project: NeT2I - Convert network data to images

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

i2net-2.3.tar.gz (14.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

i2net-2.3-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

File details

Details for the file i2net-2.3.tar.gz.

File metadata

  • Download URL: i2net-2.3.tar.gz
  • Upload date:
  • Size: 14.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for i2net-2.3.tar.gz
Algorithm Hash digest
SHA256 38281e174ff58304cf58e0beab20be50634672d56e18e91a7266e05594dbbfb2
MD5 6af1c86c9154cd486af18fa699f24534
BLAKE2b-256 dc7c9133aecd497e5d513b1db73ecac1cb84935caab4594c41e3494028ba9464

See more details on using hashes here.

File details

Details for the file i2net-2.3-py3-none-any.whl.

File metadata

  • Download URL: i2net-2.3-py3-none-any.whl
  • Upload date:
  • Size: 11.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for i2net-2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 63b582e67a72ad005338234ec1c0d37f80fd4c04bb1aeb91f5b71dcd56c05126
MD5 66e8e1e7c3a4de100d7907f6f2f48134
BLAKE2b-256 dfccd8d16fa3b457356ca394ed14c397ee0e08ff70642b1ee8d777709fed3390

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page