Skip to content

Add validate_ip_address() function for IPv4 validation and configurable IP address support - #4

Draft
blaab2 with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-a4bcbf85-8af7-487f-8959-6f5250c2eb8a
Draft

Add validate_ip_address() function for IPv4 validation and configurable IP address support#4
blaab2 with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-a4bcbf85-8af7-487f-8959-6f5250c2eb8a

Conversation

Copilot AI commented Jul 28, 2025

Copy link
Copy Markdown

This PR adds a robust IP address validation function and makes the StreamMagic device IP address configurable via command line arguments, addressing the need for proper input validation in the codebase.

Changes

New IP Validation Function

Added validate_ip_address() function that:

  • Uses Python's built-in ipaddress module for robust IPv4 validation
  • Ensures IP addresses conform to standard IPv4 format (e.g., 192.168.1.1)
  • Provides descriptive error messages for invalid inputs
  • Handles edge cases: empty strings, whitespace, non-string inputs, out-of-range octets

Configurable IP Address Support

  • Before: IP address was hardcoded as "192.168.1.29" in the source code
  • After: IP address can be specified via optional command line parameter
  • Usage: python -m rew2streammagic.main <eq_file> [ip_address]
  • Backwards compatible: Defaults to 192.168.1.29 when no IP is provided

Error Handling

The tool now validates IP addresses before attempting to connect and provides clear error messages:

# Valid IP address
$ poetry run python -m rew2streammagic.main example.txt 192.168.1.100
Using StreamMagic device at IP: 192.168.1.100

# Invalid IP address  
$ poetry run python -m rew2streammagic.main example.txt 192.168.1.300
Error: Invalid IPv4 address '192.168.1.300': Octet 300 (> 255) not permitted in '192.168.1.300'

Documentation Updates

Updated README.md with:

  • New command line syntax documentation
  • Usage examples showing both valid and invalid IP scenarios
  • Clear explanation of the optional IP parameter

Testing

  • ✅ Valid IPv4 addresses are correctly accepted
  • ✅ Invalid addresses are rejected with descriptive errors
  • ✅ Edge cases (empty, malformed, non-string inputs) handled appropriately
  • ✅ Backwards compatibility maintained with default IP
  • ✅ All existing functionality preserved
  • ✅ Code passes linting checks

This implementation provides the requested IP validation functionality while maintaining minimal, surgical changes to the existing codebase.

This pull request was created as a result of the following prompt from Copilot chat.

Add a validate_ip_address() function to validate input IP addresses in the codebase. The function should ensure that the provided IP address conforms to the standard IPv4 format (e.g., 192.168.1.1) and provide appropriate error handling for invalid inputs. Update the existing functionality that accepts IP addresses (if any) to integrate with this validation function.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

…e IP address support

Co-authored-by: blaab2 <10156348+blaab2@users.noreply.github.com>
Copilot AI changed the title [WIP] Add IP Address Validation Functionality Add validate_ip_address() function for IPv4 validation and configurable IP address support Jul 28, 2025
Copilot AI requested a review from blaab2 July 28, 2025 08:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants