ipv4-conversions 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Marco S. Tornabene
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,88 @@
1
+ Metadata-Version: 2.4
2
+ Name: ipv4-conversions
3
+ Version: 0.1.0
4
+ Summary: Convert IPv4 addresses between dotted decimal and dotted binary notation
5
+ Author: Marco S. Tornabene
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/JustM4rk123/ipv4_conversions
8
+ Keywords: ipv4,binary,decimal,conversions
9
+ Requires-Python: >=3.10
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ Requires-Dist: bin-dec-conversions>=1.0.0
13
+ Requires-Dist: questionary
14
+ Provides-Extra: dev
15
+ Requires-Dist: ruff; extra == "dev"
16
+ Requires-Dist: pytest; extra == "dev"
17
+ Dynamic: license-file
18
+
19
+ # IPv4 Conversions
20
+
21
+ `ipv4-conversions` converts an IPv4 address between dotted-decimal notation and four dotted 8-bit binary octets. It is available as a Python library, a command-line tool, and an interactive prompt.
22
+
23
+ ## Requirements
24
+
25
+ - Python 3.10 or newer
26
+ - [`bin-dec-conversions`](https://pypi.org/project/bin-dec-conversions/), which supplies the binary/decimal conversions for each octet
27
+ - [`questionary`](https://pypi.org/project/questionary/), used by the interactive prompt
28
+
29
+ ## Installation
30
+
31
+ ```bash
32
+ pip install .
33
+ ```
34
+
35
+ ## Library usage
36
+
37
+ ```python
38
+ from ipv4_conversions import binary_to_ipv4, ipv4_to_binary
39
+
40
+ ipv4_to_binary("192.168.1.1")
41
+ # "11000000.10101000.00000001.00000001"
42
+
43
+ binary_to_ipv4("11000000.10101000.00000001.00000001")
44
+ # "192.168.1.1"
45
+ ```
46
+
47
+ Both functions require exactly four octets. Decimal octets must be in the range `0` to `255`; binary octets must each contain exactly eight `0` or `1` characters. Invalid input raises `ValueError`.
48
+
49
+ | Function | Description |
50
+ | --- | --- |
51
+ | `ipv4_to_binary(ipv4: str) -> str` | Converts dotted-decimal IPv4 notation to four zero-padded, dotted binary octets. |
52
+ | `binary_to_ipv4(binary: str) -> str` | Converts four dotted 8-bit binary octets to dotted-decimal IPv4 notation. |
53
+
54
+ ## Command line
55
+
56
+ ```bash
57
+ # Binary address to dotted decimal
58
+ ipv4-conversions --to-decimal 11000000.10101000.00000001.00000001
59
+ # The dotted-decimal equivalent of ... is: 192.168.1.1
60
+
61
+ # Dotted decimal to binary address
62
+ ipv4-conversions --to-binary 192.168.1.1
63
+ # The binary equivalent of 192.168.1.1 is: 11000000.10101000.00000001.00000001
64
+ ```
65
+
66
+ The short options are `-d` for `--to-decimal` and `-b` for `--to-binary`. The options are mutually exclusive. Running `ipv4-conversions` without options opens the interactive menu.
67
+
68
+ ## Interactive menu
69
+
70
+ Run the command without any options to open the interactive menu:
71
+
72
+ ```bash
73
+ ipv4-conversions
74
+ ```
75
+
76
+ Choose **Binary address to dotted decimal** or **Dotted decimal to binary address**, then enter the address when prompted. Choose **Exit** to quit.
77
+
78
+ ## Development
79
+
80
+ ```bash
81
+ pip install -e ".[dev]"
82
+ pytest
83
+ ruff check .
84
+ ```
85
+
86
+ ## License
87
+
88
+ Released under the MIT License. See [LICENSE](LICENSE).
@@ -0,0 +1,70 @@
1
+ # IPv4 Conversions
2
+
3
+ `ipv4-conversions` converts an IPv4 address between dotted-decimal notation and four dotted 8-bit binary octets. It is available as a Python library, a command-line tool, and an interactive prompt.
4
+
5
+ ## Requirements
6
+
7
+ - Python 3.10 or newer
8
+ - [`bin-dec-conversions`](https://pypi.org/project/bin-dec-conversions/), which supplies the binary/decimal conversions for each octet
9
+ - [`questionary`](https://pypi.org/project/questionary/), used by the interactive prompt
10
+
11
+ ## Installation
12
+
13
+ ```bash
14
+ pip install .
15
+ ```
16
+
17
+ ## Library usage
18
+
19
+ ```python
20
+ from ipv4_conversions import binary_to_ipv4, ipv4_to_binary
21
+
22
+ ipv4_to_binary("192.168.1.1")
23
+ # "11000000.10101000.00000001.00000001"
24
+
25
+ binary_to_ipv4("11000000.10101000.00000001.00000001")
26
+ # "192.168.1.1"
27
+ ```
28
+
29
+ Both functions require exactly four octets. Decimal octets must be in the range `0` to `255`; binary octets must each contain exactly eight `0` or `1` characters. Invalid input raises `ValueError`.
30
+
31
+ | Function | Description |
32
+ | --- | --- |
33
+ | `ipv4_to_binary(ipv4: str) -> str` | Converts dotted-decimal IPv4 notation to four zero-padded, dotted binary octets. |
34
+ | `binary_to_ipv4(binary: str) -> str` | Converts four dotted 8-bit binary octets to dotted-decimal IPv4 notation. |
35
+
36
+ ## Command line
37
+
38
+ ```bash
39
+ # Binary address to dotted decimal
40
+ ipv4-conversions --to-decimal 11000000.10101000.00000001.00000001
41
+ # The dotted-decimal equivalent of ... is: 192.168.1.1
42
+
43
+ # Dotted decimal to binary address
44
+ ipv4-conversions --to-binary 192.168.1.1
45
+ # The binary equivalent of 192.168.1.1 is: 11000000.10101000.00000001.00000001
46
+ ```
47
+
48
+ The short options are `-d` for `--to-decimal` and `-b` for `--to-binary`. The options are mutually exclusive. Running `ipv4-conversions` without options opens the interactive menu.
49
+
50
+ ## Interactive menu
51
+
52
+ Run the command without any options to open the interactive menu:
53
+
54
+ ```bash
55
+ ipv4-conversions
56
+ ```
57
+
58
+ Choose **Binary address to dotted decimal** or **Dotted decimal to binary address**, then enter the address when prompted. Choose **Exit** to quit.
59
+
60
+ ## Development
61
+
62
+ ```bash
63
+ pip install -e ".[dev]"
64
+ pytest
65
+ ruff check .
66
+ ```
67
+
68
+ ## License
69
+
70
+ Released under the MIT License. See [LICENSE](LICENSE).
@@ -0,0 +1,38 @@
1
+ [build-system]
2
+ requires = ["setuptools >= 77.0.3"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "ipv4-conversions"
7
+ description = "Convert IPv4 addresses between dotted decimal and dotted binary notation"
8
+ version = "0.1.0"
9
+ requires-python = ">=3.10"
10
+ readme = "README.md"
11
+ license = "MIT"
12
+ license-files = ["LICENSE"]
13
+ keywords = ["ipv4", "binary", "decimal", "conversions"]
14
+ authors = [
15
+ {name = "Marco S. Tornabene"}
16
+ ]
17
+ dependencies = [
18
+ "bin-dec-conversions>=1.0.0",
19
+ "questionary",
20
+ ]
21
+
22
+ [project.optional-dependencies]
23
+ dev = [
24
+ "ruff",
25
+ "pytest",
26
+ ]
27
+
28
+ [project.urls]
29
+ Homepage = "https://github.com/JustM4rk123/ipv4_conversions"
30
+
31
+ [tool.setuptools.packages.find]
32
+ where = ["src"]
33
+
34
+ [tool.pytest.ini_options]
35
+ testpaths = ["tests"]
36
+
37
+ [project.scripts]
38
+ ipv4-conversions = "ipv4_conversions.cli:main"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,10 @@
1
+ from importlib.metadata import PackageNotFoundError, version
2
+
3
+ from .core import binary_to_ipv4, ipv4_to_binary
4
+
5
+ try:
6
+ __version__ = version("ipv4-conversions")
7
+ except PackageNotFoundError:
8
+ __version__ = "unknown"
9
+
10
+ __all__ = ["__version__", "binary_to_ipv4", "ipv4_to_binary"]
@@ -0,0 +1,85 @@
1
+ import argparse
2
+ import sys
3
+
4
+ import questionary
5
+
6
+ from .core import binary_to_ipv4, ipv4_to_binary
7
+
8
+
9
+ def main():
10
+ parser = argparse.ArgumentParser(prog="ipv4-conversions")
11
+ group = parser.add_mutually_exclusive_group()
12
+ group.add_argument(
13
+ "-d",
14
+ "--to-decimal",
15
+ dest="to_decimal",
16
+ metavar="BINARY",
17
+ type=str,
18
+ help="Convert a binary IPv4 address to dotted-decimal notation",
19
+ )
20
+ group.add_argument(
21
+ "-b",
22
+ "--to-binary",
23
+ dest="to_binary",
24
+ metavar="DECIMAL",
25
+ type=str,
26
+ help="Convert a dotted-decimal IPv4 address to binary",
27
+ )
28
+
29
+ args = parser.parse_args()
30
+
31
+ if args.to_decimal is not None:
32
+ try:
33
+ result = binary_to_ipv4(args.to_decimal)
34
+ except ValueError as e:
35
+ parser.error(str(e))
36
+ print(f"The dotted-decimal equivalent of {args.to_decimal} is: {result}")
37
+ elif args.to_binary is not None:
38
+ try:
39
+ result = ipv4_to_binary(args.to_binary)
40
+ except ValueError as e:
41
+ parser.error(str(e))
42
+ print(f"The binary equivalent of {args.to_binary} is: {result}")
43
+ else:
44
+ conversion = questionary.select(
45
+ "Which conversion do you want to perform?",
46
+ choices=[
47
+ "Binary address to dotted decimal",
48
+ "Dotted decimal to binary address",
49
+ "Exit",
50
+ ],
51
+ ).ask()
52
+
53
+ match conversion:
54
+ case "Binary address to dotted decimal":
55
+ while True:
56
+ try:
57
+ binary = input(
58
+ "Insert four dotted 8-bit binary octets: "
59
+ ).strip()
60
+ print(
61
+ f"The dotted-decimal equivalent of {binary} is: "
62
+ f"{binary_to_ipv4(binary)}"
63
+ )
64
+ except ValueError as e:
65
+ print(f"Invalid input: {e}")
66
+ else:
67
+ break
68
+ case "Dotted decimal to binary address":
69
+ while True:
70
+ try:
71
+ ipv4 = input("Insert a dotted-decimal IPv4 address: ").strip()
72
+ print(
73
+ f"The binary address equivalent of {ipv4} is: "
74
+ f"{ipv4_to_binary(ipv4)}"
75
+ )
76
+ except ValueError as e:
77
+ print(f"Invalid input: {e}")
78
+ else:
79
+ break
80
+ case "Exit":
81
+ sys.exit("Program terminated")
82
+
83
+
84
+ if __name__ == "__main__":
85
+ main()
@@ -0,0 +1,55 @@
1
+ from bin_dec_conversions import binary_to_decimal, decimal_to_binary
2
+
3
+
4
+ def ipv4_to_binary(ipv4: str) -> str:
5
+ """Convert a dotted-decimal IPv4 address to four 8-bit binary octets."""
6
+ if not ipv4:
7
+ raise ValueError("The input is empty. Enter an IPv4 address with four octets")
8
+
9
+ octets = ipv4.split(".")
10
+ if len(octets) != 4:
11
+ raise ValueError(
12
+ f"'{ipv4}' is not a valid IPv4 address: exactly four decimal octets are required"
13
+ )
14
+
15
+ binary_octets = []
16
+ for octet in octets:
17
+ if not octet or not octet.isascii() or not octet.isdigit():
18
+ raise ValueError(
19
+ f"'{ipv4}' is not a valid IPv4 address: "
20
+ f"'{octet}' is not a decimal octet"
21
+ )
22
+
23
+ decimal = int(octet)
24
+ if decimal > 255:
25
+ raise ValueError(
26
+ f"'{ipv4}' is not a valid IPv4 address: "
27
+ f"octet '{octet}' is outside the range 0-255"
28
+ )
29
+ binary_octets.append(decimal_to_binary(decimal, 8))
30
+
31
+ return ".".join(binary_octets)
32
+
33
+
34
+ def binary_to_ipv4(binary: str) -> str:
35
+ """Convert four dotted 8-bit binary octets to a dotted-decimal IPv4 address."""
36
+ if not binary:
37
+ raise ValueError("The input is empty. Enter four 8-bit binary octets")
38
+
39
+ octets = binary.split(".")
40
+ if len(octets) != 4:
41
+ raise ValueError(
42
+ f"'{binary}' is not a valid IPv4 binary address: "
43
+ "exactly four 8-bit binary octets are required"
44
+ )
45
+
46
+ decimal_octets = []
47
+ for octet in octets:
48
+ if len(octet) != 8:
49
+ raise ValueError(
50
+ f"'{binary}' is not a valid IPv4 binary address: "
51
+ f"octet '{octet}' must contain exactly 8 bits"
52
+ )
53
+ decimal_octets.append(str(binary_to_decimal(octet)))
54
+
55
+ return ".".join(decimal_octets)
@@ -0,0 +1,88 @@
1
+ Metadata-Version: 2.4
2
+ Name: ipv4-conversions
3
+ Version: 0.1.0
4
+ Summary: Convert IPv4 addresses between dotted decimal and dotted binary notation
5
+ Author: Marco S. Tornabene
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/JustM4rk123/ipv4_conversions
8
+ Keywords: ipv4,binary,decimal,conversions
9
+ Requires-Python: >=3.10
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ Requires-Dist: bin-dec-conversions>=1.0.0
13
+ Requires-Dist: questionary
14
+ Provides-Extra: dev
15
+ Requires-Dist: ruff; extra == "dev"
16
+ Requires-Dist: pytest; extra == "dev"
17
+ Dynamic: license-file
18
+
19
+ # IPv4 Conversions
20
+
21
+ `ipv4-conversions` converts an IPv4 address between dotted-decimal notation and four dotted 8-bit binary octets. It is available as a Python library, a command-line tool, and an interactive prompt.
22
+
23
+ ## Requirements
24
+
25
+ - Python 3.10 or newer
26
+ - [`bin-dec-conversions`](https://pypi.org/project/bin-dec-conversions/), which supplies the binary/decimal conversions for each octet
27
+ - [`questionary`](https://pypi.org/project/questionary/), used by the interactive prompt
28
+
29
+ ## Installation
30
+
31
+ ```bash
32
+ pip install .
33
+ ```
34
+
35
+ ## Library usage
36
+
37
+ ```python
38
+ from ipv4_conversions import binary_to_ipv4, ipv4_to_binary
39
+
40
+ ipv4_to_binary("192.168.1.1")
41
+ # "11000000.10101000.00000001.00000001"
42
+
43
+ binary_to_ipv4("11000000.10101000.00000001.00000001")
44
+ # "192.168.1.1"
45
+ ```
46
+
47
+ Both functions require exactly four octets. Decimal octets must be in the range `0` to `255`; binary octets must each contain exactly eight `0` or `1` characters. Invalid input raises `ValueError`.
48
+
49
+ | Function | Description |
50
+ | --- | --- |
51
+ | `ipv4_to_binary(ipv4: str) -> str` | Converts dotted-decimal IPv4 notation to four zero-padded, dotted binary octets. |
52
+ | `binary_to_ipv4(binary: str) -> str` | Converts four dotted 8-bit binary octets to dotted-decimal IPv4 notation. |
53
+
54
+ ## Command line
55
+
56
+ ```bash
57
+ # Binary address to dotted decimal
58
+ ipv4-conversions --to-decimal 11000000.10101000.00000001.00000001
59
+ # The dotted-decimal equivalent of ... is: 192.168.1.1
60
+
61
+ # Dotted decimal to binary address
62
+ ipv4-conversions --to-binary 192.168.1.1
63
+ # The binary equivalent of 192.168.1.1 is: 11000000.10101000.00000001.00000001
64
+ ```
65
+
66
+ The short options are `-d` for `--to-decimal` and `-b` for `--to-binary`. The options are mutually exclusive. Running `ipv4-conversions` without options opens the interactive menu.
67
+
68
+ ## Interactive menu
69
+
70
+ Run the command without any options to open the interactive menu:
71
+
72
+ ```bash
73
+ ipv4-conversions
74
+ ```
75
+
76
+ Choose **Binary address to dotted decimal** or **Dotted decimal to binary address**, then enter the address when prompted. Choose **Exit** to quit.
77
+
78
+ ## Development
79
+
80
+ ```bash
81
+ pip install -e ".[dev]"
82
+ pytest
83
+ ruff check .
84
+ ```
85
+
86
+ ## License
87
+
88
+ Released under the MIT License. See [LICENSE](LICENSE).
@@ -0,0 +1,14 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ src/ipv4_conversions/__init__.py
5
+ src/ipv4_conversions/cli.py
6
+ src/ipv4_conversions/core.py
7
+ src/ipv4_conversions.egg-info/PKG-INFO
8
+ src/ipv4_conversions.egg-info/SOURCES.txt
9
+ src/ipv4_conversions.egg-info/dependency_links.txt
10
+ src/ipv4_conversions.egg-info/entry_points.txt
11
+ src/ipv4_conversions.egg-info/requires.txt
12
+ src/ipv4_conversions.egg-info/top_level.txt
13
+ tests/test_conversions.py
14
+ tests/test_invalid.py
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ ipv4-conversions = ipv4_conversions.cli:main
@@ -0,0 +1,6 @@
1
+ bin-dec-conversions>=1.0.0
2
+ questionary
3
+
4
+ [dev]
5
+ ruff
6
+ pytest
@@ -0,0 +1 @@
1
+ ipv4_conversions
@@ -0,0 +1,35 @@
1
+ import pytest
2
+
3
+ from ipv4_conversions import binary_to_ipv4, ipv4_to_binary
4
+
5
+
6
+ @pytest.mark.parametrize(
7
+ "ipv4, expected",
8
+ [
9
+ ("0.0.0.0", "00000000.00000000.00000000.00000000"),
10
+ ("255.255.255.255", "11111111.11111111.11111111.11111111"),
11
+ ("192.168.1.1", "11000000.10101000.00000001.00000001"),
12
+ ("10.0.0.5", "00001010.00000000.00000000.00000101"),
13
+ ],
14
+ )
15
+ def test_ipv4_to_binary(ipv4, expected):
16
+ assert ipv4_to_binary(ipv4) == expected
17
+
18
+
19
+ @pytest.mark.parametrize(
20
+ "binary, expected",
21
+ [
22
+ ("00000000.00000000.00000000.00000000", "0.0.0.0"),
23
+ ("11111111.11111111.11111111.11111111", "255.255.255.255"),
24
+ ("11000000.10101000.00000001.00000001", "192.168.1.1"),
25
+ ("00001010.00000000.00000000.00000101", "10.0.0.5"),
26
+ ],
27
+ )
28
+ def test_binary_to_ipv4(binary, expected):
29
+ assert binary_to_ipv4(binary) == expected
30
+
31
+
32
+ @pytest.mark.parametrize("octet", range(256))
33
+ def test_round_trip_each_octet(octet):
34
+ ipv4 = f"{octet}.0.127.255"
35
+ assert binary_to_ipv4(ipv4_to_binary(ipv4)) == ipv4
@@ -0,0 +1,34 @@
1
+ import re
2
+
3
+ import pytest
4
+
5
+ from ipv4_conversions import binary_to_ipv4, ipv4_to_binary
6
+
7
+
8
+ @pytest.mark.parametrize(
9
+ "invalid, expected_in_message",
10
+ [
11
+ ("", "empty"),
12
+ ("192.168.1", "four decimal octets"),
13
+ ("192.168.1.256", "outside the range 0-255"),
14
+ ("192.168.a.1", "not a decimal octet"),
15
+ ("192..1.1", "not a decimal octet"),
16
+ ],
17
+ )
18
+ def test_ipv4_to_binary_invalid_input(invalid, expected_in_message):
19
+ with pytest.raises(ValueError, match=re.escape(expected_in_message)):
20
+ ipv4_to_binary(invalid)
21
+
22
+
23
+ @pytest.mark.parametrize(
24
+ "invalid, expected_in_message",
25
+ [
26
+ ("", "empty"),
27
+ ("11000000.10101000.00000001", "four 8-bit binary octets"),
28
+ ("1100000.10101000.00000001.00000001", "exactly 8 bits"),
29
+ ("11000000.10101000.0000000a.00000001", "invalid character"),
30
+ ],
31
+ )
32
+ def test_binary_to_ipv4_invalid_input(invalid, expected_in_message):
33
+ with pytest.raises(ValueError, match=re.escape(expected_in_message)):
34
+ binary_to_ipv4(invalid)