| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
This repository contains a Python script that validates IPv4 addresses using regular expressions (Regex). It also includes a set of pytest tests to ensure that the validator behaves as expected.
IPv4 Address Validation:
The script checks if a given string is a valid IPv4 address. An address is considered valid if it consists of four octets separated by dots, with each octet being a number between 0 and 255.
Regex-Based Implementation:
The validation logic is implemented using a concise and efficient regular expression that matches the criteria for IPv4 addresses.
Automated Testing:
The repository includes tests written with pytest to verify the correctness of the IPv4 address validation function. This helps maintain code quality and ensures that changes do not break the intended functionality.
IPv4_Address.py
This file contains the main implementation of the IPv4 validation function and the script’s entry point. It reads an IPv4 address from user input and prints whether the address is valid (True) or not (False).
test_ipv4_address.py
This file contains a series of pytest tests. The tests are designed to cover:
Python 3.x: Make sure you have Python 3 installed.
pytest: Install pytest for running tests. You can install it using pip:
pip install pytestTo run the IPv4 address validator, execute the following command in your terminal:
python IPv4_Address.pyYou will be prompted to enter an IPv4 address. The script will output True if the address is valid and False otherwise.
To run the automated tests, simply run:
pytest test_ipv4_address.pypytest will discover the tests and display the results, ensuring that all cases pass as expected.
validate(ip: str) -> bool:
This function uses a regular expression to check whether the input string is a valid IPv4 address. The regex ensures:
main():
The main function that prompts the user for an IPv4 address, calls the validation function, and prints the result.
Feel free to fork this repository and submit pull requests if you have suggestions or improvements. For major changes, please open an issue first to discuss what you would like to change.
This project is licensed under the MIT License. See the LICENSE file for more details.
| Back | FazBrowse Home | New Git URL |