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

# Decode all images in directory
results = i2net.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

# Custom configuration with separate type files
results = i2net.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

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

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

Using the Enhanced Decoder Class

from i2net 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.5.2.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.5.2-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: i2net-2.5.2.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.5.2.tar.gz
Algorithm Hash digest
SHA256 0a118431ca65557ecf83eca7c6b2947709c43115254842fcb0d8cbf504886e48
MD5 67bf17cc0708f53857c2e21f7ab489a4
BLAKE2b-256 87cfb5d418f005d578e40009d1ca2f9c87524b2236e03346570ebb18462370f4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: i2net-2.5.2-py3-none-any.whl
  • Upload date:
  • Size: 11.3 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.5.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f5c2f8c0bf04d612a9d2a26c90da3bb388f6936279c0816681813beab14d8999
MD5 864cce7d340d6cf38b350c130b89f975
BLAKE2b-256 e13f5a9953510e56b06234843e89c2781f0ab0c02064f3528bca1648b46d1fe3

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