This an IP address calculator.
I'm a savy CyberSecurity professional, and the propose of this code is provide and an example and also incentivate my graduation students to develop tools and scripts in python to do defensive or ofensive security tasks.
Features:
- Works with IPv6 and IPv4.
- Convert address to decimal, hexadecimal and bnary form.
- Valdiate addresses
- Calculate nets (Broadcast, Network ID and avaliable host address)
- Calculate Subnets
You can use this tool in many ways:
With this command, you PC will download the app from https://pypi.org/project/my-ip-calulator/:
pip install my-ip-calc
With this commands:
docker push brunobotelhobr/my-ip-calulator:latest
docker run --rm brunobotelhobr/my-ip-calulator:latest
You mus have python installed.
pip install poetry
git clone https://github.com/brunobotelhobr/My-IP-Calculator.git
cd My-IP-Calculator
poetry shell
poetry install
# Testing
task test
# Run
python src/app/cmd.py
General:
Usage: my-ip-calculator [OPTIONS] COMMAND [ARGS]...
Options:
--install-completion Install completion for the current shell.
--show-completion Show completion for the current shell, to copy it or customize the installation.
--help Show this message and exit.
Commands:
net Calculate the network address from an IP address and a subnet mask, output the address in the desired format.
subnet Split an IP address into network and host parts, output the address in the desired format.
val Validate an IPv4 ou IPv6 address, output the address in the desired format.
version Show version.
Show the software version:
my-ip-calculator version
0.0.2
Usage: my-ip-calculator [OPTIONS] ADDRESS
Validate an IPv4 ou IPv6 address, output the address in the desired format.
Arguments
* address TEXT IP address, it supports IPv4 and IPv6 [default: None] [required]
Options
--output -o [bin|hex|dec] Output format for the network address details of an IP address, it supports bin, hex, dec. [default: None]
--help Show this message and exit.
Examples
my-ip-calculator val 10.10.10.10
Address
βββββββββββ³ββββββββββββββββββ³βββββββββ
β Item β Value β Status β
β‘βββββββββββββββββββββββββββββββββββββ©
β Version β 4 β β
OK β
β Address β 010.010.010.010 β β
OK β
βββββββββββ΄ββββββββββββββββββ΄βββββββββ
my-ip-calculator val 10.10.10.10 -o bin
Address
βββββββββββ³ββββββββββββββββββββββββββββββββββββββ³βββββββββ
β Item β Value β Status β
β‘βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ©
β Version β 4 β β
OK β
β Address β 00001010.00001010.00001010.00001010 β β
OK β
βββββββββββ΄ββββββββββββββββββββββββββββββββββββββ΄βββββββββ
my-ip-calculator val 10.10.10.10 -o hex
Address
βββββββββββ³ββββββββββββββ³βββββββββ
β Item β Value β Status β
β‘βββββββββββββββββββββββββββββββββ©
β Version β 4 β β
OK β
β Address β 0A.0A.0A.0A β β
OK β
βββββββββββ΄ββββββββββββββ΄βββββββββ
my-ip-calculator val 1:2:3:4:5:6:7:8
Address
βββββββββββ³ββββββββββββββββββββββββββββββββββββββββββ³βββββββββ
β Item β Value β Status β
β‘βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ©
β Version β 6 β β
OK β
β Address β 0001:0002:0003:0004:0005:0006:0007:0008 β β
OK β
βββββββββββ΄ββββββββββββββββββββββββββββββββββββββββββ΄βββββββββ
my-ip-calculator val 1:2:3::
Address
βββββββββββ³ββββββββββββββββββββββββββββββββββββββββββ³βββββββββ
β Item β Value β Status β
β‘βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ©
β Version β 6 β β
OK β
β Address β 0001:0002:0003:0000:0000:0000:0000:0000 β β
OK β
βββββββββββ΄ββββββββββββββββββββββββββββββββββββββββββ΄βββββββββ
my-ip-calculator val A -o hex
Errors
βββββββββββ³ββββββββ³ββββββββββββββββββ³βββββββββββββ
β Item β Value β Message β Status β
β‘βββββββββββββββββββββββββββββββββββββββββββββββββ©
β address β A β Invalid address β β Invalid β
βββββββββββ΄ββββββββ΄ββββββββββββββββββ΄βββββββββββββ
Usage: my-ip-calculator net [OPTIONS] ADDRESS [MASK]
Calculate the network address from an IP address and a subnet mask, output the address in the desired format.
if a mask isn't provided:
- For IPv4 it will provide a mask based on the adress class: A, B,C,D and E
- For IPv6 a standart /64 will be provided.
Arguments
* address TEXT IP address, it supports IPv4 and IPv6. [default: None] [required]
mask [MASK] IP address mask, if not provided an auto generated one will be assigned. [default:None]
Options
--output -o [bin|hex|dec] Output format for the network address details of an IP address, it supports bin, hex, dec. [default:None]
--help Show this message and exit.
Examples
my-ip-calculator net 192.168.0.1
Network
βββββββββββββββ³ββββββββββββββββββ³βββββββββ
β Item β Value β Status β
β‘βββββββββββββββββββββββββββββββββββββββββ©
β Version β 4 β β
OK β
β Address β 192.168.000.001 β β
OK β
β Mask β 255.255.255.000 β β
OK β
β Network β 192.168.000.000 β β
OK β
β Broadcast β 192.168.000.255 β β
OK β
β Hosts (dec) β 254 β β
OK β
βββββββββββββββ΄ββββββββββββββββββ΄βββββββββ
my-ip-calculator net 192.168.0.1 16
Network
βββββββββββββββ³ββββββββββββββββββ³βββββββββ
β Item β Value β Status β
β‘βββββββββββββββββββββββββββββββββββββββββ©
β Version β 4 β β
OK β
β Address β 192.168.000.001 β β
OK β
β Mask β 255.255.000.000 β β
OK β
β Network β 192.168.000.000 β β
OK β
β Broadcast β 192.168.255.255 β β
OK β
β Hosts (dec) β 65534 β β
OK β
βββββββββββββββ΄ββββββββββββββββββ΄βββββββββ
my-ip-calculator net 192.168.0.1 16 -o hex
Network
βββββββββββββββ³ββββββββββββββ³βββββββββ
β Item β Value β Status β
β‘βββββββββββββββββββββββββββββββββββββ©
β Version β 4 β β
OK β
β Address β C0.A8.00.01 β β
OK β
β Mask β FF.FF.00.00 β β
OK β
β Network β C0.A8.00.00 β β
OK β
β Broadcast β C0.A8.FF.FF β β
OK β
β Hosts (dec) β 65534 β β
OK β
βββββββββββββββ΄ββββββββββββββ΄βββββββββ
my-ip-calculator net 192.168.0.1 16 -o bin
Network
βββββββββββββββ³ββββββββββββββββββββββββββββββββββββββ³βββββββββ
β Item β Value β Status β
β‘βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ©
β Version β 4 β β
OK β
β Address β 11000000.10101000.00000000.00000001 β β
OK β
β Mask β 11111111.11111111.00000000.00000000 β β
OK β
β Network β 11000000.10101000.00000000.00000000 β β
OK β
β Broadcast β 11000000.10101000.11111111.11111111 β β
OK β
β Hosts (dec) β 65534 β β
OK β
βββββββββββββββ΄ββββββββββββββββββββββββββββββββββββββ΄βββββββββ
my-ip-calculator net 1:2:3:4:5:6:A:B -o hex
Network
βββββββββββββββ³ββββββββββββββββββββββββββββββββββββββββββ³βββββββββ
β Item β Value β Status β
β‘βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ©
β Version β 6 β β
OK β
β Address β 0001:0002:0003:0004:0005:0006:000A:000B β β
OK β
β Mask β FFFF:FFFF:FFFF:FFFF:0000:0000:0000:0000 β β
OK β
β Network β 0001:0002:0003:0004:0000:0000:0000:0000 β β
OK β
β Broadcast β 0001:0002:0003:0004:FFFF:FFFF:FFFF:FFFF β β
OK β
β Hosts (dec) β 18446744073709551614 β β
OK β
βββββββββββββββ΄ββββββββββββββββββββββββββββββββββββββββββ΄βββββββββ
my-ip-calculator net 1:2:3:4:5:6:A:B 96 -o hex
Network
βββββββββββββββ³ββββββββββββββββββββββββββββββββββββββββββ³βββββββββ
β Item β Value β Status β
β‘βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ©
β Version β 6 β β
OK β
β Address β 0001:0002:0003:0004:0005:0006:000A:000B β β
OK β
β Mask β FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:0000:0000 β β
OK β
β Network β 0001:0002:0003:0004:0005:0006:0000:0000 β β
OK β
β Broadcast β 0001:0002:0003:0004:0005:0006:FFFF:FFFF β β
OK β
β Hosts (dec) β 4294967294 β β
OK β
βββββββββββββββ΄ββββββββββββββββββββββββββββββββββββββββββ΄βββββββββ
my-ip-calculator net 12:A:Z:: -o hex
Errors
βββββββββββ³ββββββββββββββββββββββββββββββββββββββββββ³ββββββββββββββββββ³βββββββββββββ
β Item β Value β Message β Status β
β‘βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ©
β address β 0012:000A:000Z:0000:0000:0000:0000:0000 β Invalid address β β Invalid β
βββββββββββ΄ββββββββββββββββββββββββββββββββββββββββββ΄ββββββββββββββββββ΄βββββββββββββ
my-ip-calculator net Z -o hex
Errors
βββββββββββ³ββββββββ³ββββββββββββββββββ³βββββββββββββ
β Item β Value β Message β Status β
β‘βββββββββββββββββββββββββββββββββββββββββββββββββ©
β address β A β Invalid address β β Invalid β
βββββββββββ΄ββββββββ΄ββββββββββββββββββ΄βββββββββββββ
Usage: cmd.py subnet [OPTIONS] ADDRESS MASK PARTS
Split an IP address into network and host parts, output the address in the desired format.
Arguments
* address TEXT IP address, it supports IPv4 and IPv6. [default: None][required]
* mask TEXT IP address mask. [default: None] [required]β
* parts INTEGER Split the netork into this parts. [default: None] [required]β
Options
--output -o TEXT Output format for the network address details of an IP address, it supports bin, hex, dec. [default: None]
--help Show this message and
Examples
my-ip-calculator subnet 192.168.0.1 8 8
Networks
βββββββββββ³ββββββββββββββββββ³ββββββββββββββββββ³ββββββββββββββββββ³ββββββββββββββ³βββββββββ
β Version β Network β Mask β Broadcast β Hosts (dec) β Status β
β‘βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ©
β 4 β 192.168.000.000 β 255.255.000.000 β 192.168.255.255 β 65534 β β
OK β
β 4 β 192.169.000.000 β 255.255.000.000 β 192.169.255.255 β 65534 β β
OK β
β 4 β 192.170.000.000 β 255.255.000.000 β 192.170.255.255 β 65534 β β
OK β
β 4 β 192.171.000.000 β 255.255.000.000 β 192.171.255.255 β 65534 β β
OK β
β 4 β 192.172.000.000 β 255.255.000.000 β 192.172.255.255 β 65534 β β
OK β
β 4 β 192.173.000.000 β 255.255.000.000 β 192.173.255.255 β 65534 β β
OK β
β 4 β 192.174.000.000 β 255.255.000.000 β 192.174.255.255 β 65534 β β
OK β
β 4 β 192.175.000.000 β 255.255.000.000 β 192.175.255.255 β 65534 β β
OK β
βββββββββββ΄ββββββββββββββββββ΄ββββββββββββββββββ΄ββββββββββββββββββ΄ββββββββββββββ΄βββββββββ
my-ip-calculator subnet 192.168.0.1 8 8 -o hex
Networks
βββββββββββ³ββββββββββββββ³ββββββββββββββ³ββββββββββββββ³ββββββββββββββ³βββββββββ
β Version β Network β Mask β Broadcast β Hosts (dec) β Status β
β‘βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ©
β 4 β C0.A8.00.00 β FF.FF.00.00 β C0.A8.FF.FF β 65534 β β
OK β
β 4 β C0.A9.00.00 β FF.FF.00.00 β C0.A9.FF.FF β 65534 β β
OK β
β 4 β C0.AA.00.00 β FF.FF.00.00 β C0.AA.FF.FF β 65534 β β
OK β
β 4 β C0.AB.00.00 β FF.FF.00.00 β C0.AB.FF.FF β 65534 β β
OK β
β 4 β C0.AC.00.00 β FF.FF.00.00 β C0.AC.FF.FF β 65534 β β
OK β
β 4 β C0.AD.00.00 β FF.FF.00.00 β C0.AD.FF.FF β 65534 β β
OK β
β 4 β C0.AE.00.00 β FF.FF.00.00 β C0.AE.FF.FF β 65534 β β
OK β
β 4 β C0.AF.00.00 β FF.FF.00.00 β C0.AF.FF.FF β 65534 β β
OK β
βββββββββββ΄ββββββββββββββ΄ββββββββββββββ΄ββββββββββββββ΄ββββββββββββββ΄βββββββββ
my-ip-calculator subnet A:B:C:D:E:: 96 16 -o dec
Networks
βββββββββββ³ββββββββββββββββββββββββββββββββββββββββββββββββββ³ββββββββββββββββββββββββββββββββββββββββββββββββββ³ββββββββββββββββββββββββββββββββββββββββββββββββββ³ββββββββββββββ³βββββββββ
β Version β Network β Mask β Broadcast β Hosts (dec) β Status β
β‘βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ©
β 6 β 00010:00011:00012:00013:00014:00000:00000:00000 β 65535:65535:65535:65535:65535:65535:65535:00000 β 00010:00011:00012:00013:00014:00000:00000:65535 β 65534 β β
OK β
β 6 β 00010:00011:00012:00013:00014:00000:00001:00000 β 65535:65535:65535:65535:65535:65535:65535:00000 β 00010:00011:00012:00013:00014:00000:00001:65535 β 65534 β β
OK β
β 6 β 00010:00011:00012:00013:00014:00000:00002:00000 β 65535:65535:65535:65535:65535:65535:65535:00000 β 00010:00011:00012:00013:00014:00000:00002:65535 β 65534 β β
OK β
β 6 β 00010:00011:00012:00013:00014:00000:00003:00000 β 65535:65535:65535:65535:65535:65535:65535:00000 β 00010:00011:00012:00013:00014:00000:00003:65535 β 65534 β β
OK β
β 6 β 00010:00011:00012:00013:00014:00000:00004:00000 β 65535:65535:65535:65535:65535:65535:65535:00000 β 00010:00011:00012:00013:00014:00000:00004:65535 β 65534 β β
OK β
β 6 β 00010:00011:00012:00013:00014:00000:00005:00000 β 65535:65535:65535:65535:65535:65535:65535:00000 β 00010:00011:00012:00013:00014:00000:00005:65535 β 65534 β β
OK β
β 6 β 00010:00011:00012:00013:00014:00000:00006:00000 β 65535:65535:65535:65535:65535:65535:65535:00000 β 00010:00011:00012:00013:00014:00000:00006:65535 β 65534 β β
OK β
β 6 β 00010:00011:00012:00013:00014:00000:00007:00000 β 65535:65535:65535:65535:65535:65535:65535:00000 β 00010:00011:00012:00013:00014:00000:00007:65535 β 65534 β β
OK β
β 6 β 00010:00011:00012:00013:00014:00000:00008:00000 β 65535:65535:65535:65535:65535:65535:65535:00000 β 00010:00011:00012:00013:00014:00000:00008:65535 β 65534 β β
OK β
β 6 β 00010:00011:00012:00013:00014:00000:00009:00000 β 65535:65535:65535:65535:65535:65535:65535:00000 β 00010:00011:00012:00013:00014:00000:00009:65535 β 65534 β β
OK β
β 6 β 00010:00011:00012:00013:00014:00000:00010:00000 β 65535:65535:65535:65535:65535:65535:65535:00000 β 00010:00011:00012:00013:00014:00000:00010:65535 β 65534 β β
OK β
β 6 β 00010:00011:00012:00013:00014:00000:00011:00000 β 65535:65535:65535:65535:65535:65535:65535:00000 β 00010:00011:00012:00013:00014:00000:00011:65535 β 65534 β β
OK β
β 6 β 00010:00011:00012:00013:00014:00000:00012:00000 β 65535:65535:65535:65535:65535:65535:65535:00000 β 00010:00011:00012:00013:00014:00000:00012:65535 β 65534 β β
OK β
β 6 β 00010:00011:00012:00013:00014:00000:00013:00000 β 65535:65535:65535:65535:65535:65535:65535:00000 β 00010:00011:00012:00013:00014:00000:00013:65535 β 65534 β β
OK β
β 6 β 00010:00011:00012:00013:00014:00000:00014:00000 β 65535:65535:65535:65535:65535:65535:65535:00000 β 00010:00011:00012:00013:00014:00000:00014:65535 β 65534 β β
OK β
β 6 β 00010:00011:00012:00013:00014:00000:00015:00000 β 65535:65535:65535:65535:65535:65535:65535:00000 β 00010:00011:00012:00013:00014:00000:00015:65535 β 65534 β β
OK β
βββββββββββ΄ββββββββββββββββββββββββββββββββββββββββββββββββββ΄ββββββββββββββββββββββββββββββββββββββββββββββββββ΄ββββββββββββββββββββββββββββββββββββββββββββββββββ΄ββββββββββββββ΄βββββββββ
It uses Poetry for dependency management and includes pre-configured tools such as black, flake8, mypy, pylint, pytest, and others, for formatting, linting, testing, and documentation management. The project also includes security tools like trivy and bandit.
The pyproject.toml file contains various configurations like project metadata, dependencies, build system, and commands for release and documentation management.
To have more details, check the Documentation
- Project Management
- β Poetry
- β Script to manage project metadata (Name, Version, Description, etc)
- β Script to Upgrade all dependencies
- β Script to clean all temporary files
- Code Formatting
- Code Linting
- Testing
- Security
- Autoamtion commands
- β Taskipy
- PyPI
- β Scripts to build and publish to PyPI
- Docker
- β Scripts to build and publish to Docker Hub
- Documentation
- β MkDocs
- β MkDocs Material Theme
- β MkDocs Versioning with mike
- β Scripts to generate SBOM (Software Bill of Materials)
- β Scripts to generate requirements.txt
- CI/CD
- β GitHub Actions to do CI/CD
This project uses Taskipy to automate common development tasks.
All tasks are defined in the pypoject.toml
file.
Almost all tools used in this project uses pyproject.toml
to store their configurations.
List of preset tasks:
pre-commit Run all pre-commit tasks
pre-release Run all pre-release tasks
----------- ----------------------------------------
info Show project info
meta Update project properties
upgrade Upgrade all dependencies
sec Run all security checks
format Run all formaters
lint Run all linters
bom Generate BOM
req Generate requirements.txt
test Run all tests
pypi-build Build package for PyPI
pypi-auth Authenticate to PyPI
pypi-pub Publish package to PyPI
docker-list List docker images
docker-build Build docker image
docker-sec-scan Scan a docker image looking for vulenrabilities
docker-auth Authenticate to Docker Hub
docker-latest Tag a docker image as latest
docker-pub Publish docker image to Docker Hub
docs Run docs server
docs-list List docs versions
docs-build Add a new version to docs
docs-delete Delete a version of the docs
docs-latest Set the latest Version.
docs-purge Purge all versions of the docs.
docs-pub Publish documentation to the doc branch on GitHub.
clean Clean all generated files
You must install manually the following tools:
Be sure you have installed all the requirements and that you on the desired python Version, you can check it with:
python --version
# Clone the repository
git clone https://github.com/brunobotelhobr/My-IP-Calculator.git
# Check the python version, you must use the version that the project will use.
python -V
# Install the dependencies
pip install poetry
poetry shell
poetry install
# Check the taskipi commands:
task --list
# Update projetct metadata
task meta
# Clone the repository
git clone
# Check the python version, you must use the version that the project will use.
python -V
# Install the dependencies
pip install poetry
poetry shell
poetry install
# Check the taskipi commands:
task --list
# Create a new branch
git checkout -b <branch-name>
# Check for lint errors
task format
task lint
# Check for security errors
task sec
# Update the meta
task meta
task bom
task req
# Add the changes
git add .
git commit -m "feat: add a new feature"
git push origin <branch-name>
- How add a Dev Package
poetry add --dev <package-name>
- How add a Prod Package
poetry add <package-name>
- How add a Package with extras
poetry add <package-name> -E <extras>
- How remove a Package
poetry remove <package-name>
We invite you to contribute to this repository and help us make it even better. Whether it's bug fixes, new features, or documentation improvements, we welcome all contributions. Please read our documentation for guidelines on how to contribute. Happy coding!
check the Documentation for more details.