Skip to content

Commit cfe768b

Browse files
authored
Merge pull request #7 from lancalc/special-ipv4-ranges
Add support for special IPv4 range detection and handling
2 parents 936d92b + 59e2edf commit cfe768b

File tree

7 files changed

+964
-328
lines changed

7 files changed

+964
-328
lines changed

.flake8

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
11
[flake8]
2-
max-line-length = 180
2+
max-line-length = 180
3+
# extend-ignore = E501
4+
exclude =
5+
.git,
6+
__pycache__,
7+
*.egg-info,
8+
build,
9+
dist

README.md

Lines changed: 83 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -94,22 +94,17 @@ Hosts: 254
9494
**JSON mode** (`--json`):
9595
```json
9696
{
97-
"Network": "192.168.1.0",
98-
"Prefix": "/24",
99-
"Netmask": "255.255.255.0",
100-
"Broadcast": "192.168.1.255",
101-
"Hostmin": "192.168.1.1",
102-
"Hostmax": "192.168.1.254",
103-
"Hosts": "254"
97+
"network": "192.168.1.0",
98+
"prefix": "/24",
99+
"netmask": "255.255.255.0",
100+
"broadcast": "192.168.1.255",
101+
"hostmin": "192.168.1.1",
102+
"hostmax": "192.168.1.254",
103+
"hosts": "254",
104+
"comment": ""
104105
}
105106
```
106107

107-
### Special Cases
108-
109-
- **/31 networks**: Show `2*` in Hosts field - both addresses are usable (RFC 3021)
110-
- **/32 networks**: Show `1*` in Hosts field - single host network
111-
- The asterisk (*) indicates special network types where all addresses are usable
112-
113108
### Uninstall
114109

115110
```bash
@@ -197,18 +192,88 @@ Distributed under the MIT License. See LICENSE for more information.
197192
## Notes
198193

199194
A /31 mask allows the use of 2 addresses. The first will be the network address, the last the broadcast address, and for connecting hosts we use these same addresses.
200-
201195
Limitations when using a /31 prefix:
202-
203196
Protocols that use L3 broadcast stop working.
204197
In fact, at present there are almost no protocols left that rely on L3 broadcast in their operation. The main currently relevant protocols, such as OSPF, IS-IS, EIGRP, and BGP, use multicast or unicast addresses instead.
205198
This limitation can even be seen as an advantage, because it increases resistance to DoS attacks based on broadcast traffic distribution.
206-
207-
Not all devices support /31 prefixes.
199+
But not all devices support /31 prefixes.
208200
On Juniper and Cisco devices, you can safely use a /31 mask, although Cisco will issue a warning (% Warning: use /31 mask on non point-to-point interface cautiously).
209201
ZyXEL, however, does not allow you to select a /31 mask at all.
210202
As a result, there are additional limitations in network operation — from using equipment of different manufacturers to even using equipment from the same vendor but with different firmware versions.
211-
212203
If you are not concerned by the above limitations, you can confidently save addresses by using the /31 prefix.
213204

214205
The use of the /31 prefix is described in detail in RFC 3021 — Using 31-Bit Prefixes on IPv4 Point-to-Point Links.
206+
207+
208+
## Special IPv4 Ranges and Cases
209+
210+
### Special Network Types
211+
212+
- **/31 networks**: Show `2*` in Hosts field - both addresses are usable (RFC 3021)
213+
- **/32 networks**: Show `1*` in Hosts field - single host network
214+
- The asterisk (*) indicates special network types where all addresses are usable
215+
216+
### Special IPv4 Address Ranges
217+
218+
LanCalc automatically detects and handles special IPv4 address ranges according to RFC specifications. For these ranges, host-related fields show "*" and a message field indicates the range type with RFC reference.
219+
220+
#### Supported Special Ranges
221+
222+
| Range | Type | RFC | Description |
223+
|-------|------|-----|-------------|
224+
| **127.0.0.0/8** | Loopback | [RFC 3330](docs/RFC.md#rfc-3330---loopback-addresses) | Loopback addresses - not routable on the Internet |
225+
| **169.254.0.0/16** | Link-local | [RFC 3927](docs/RFC.md#rfc-3927---link-local-addresses) | Link-local addresses - not routable |
226+
| **224.0.0.0/4** | Multicast | [RFC 5771](docs/RFC.md#rfc-5771---multicast-addresses) | Multicast addresses - not for host addressing |
227+
| **0.0.0.0/8** | Unspecified | [RFC 1122](docs/RFC.md#rfc-1122---unspecified-addresses) | Unspecified addresses - not for host addressing |
228+
| **255.255.255.255/32** | Broadcast | [RFC 919](docs/RFC.md#rfc-919---broadcast-address) | Limited broadcast address - not for host addressing |
229+
230+
#### Special Range Behavior
231+
232+
When you enter an address from a special range:
233+
234+
**CLI Text Mode:**
235+
```bash
236+
lancalc 127.0.0.1/8
237+
```
238+
```
239+
Network: 127.0.0.0
240+
Prefix: /8
241+
Netmask: 255.0.0.0
242+
Broadcast: *
243+
Hostmin: 127.0.0.1
244+
Hostmax: 127.255.255.254
245+
Hosts: 16777214
246+
Comment: RFC 3330 Loopback (https://github.com/lancalc/lancalc/blob/main/docs/RFC.md#rfc-3330---loopback-addresses)
247+
```
248+
249+
**CLI JSON Mode:**
250+
```bash
251+
lancalc 224.0.0.1/4 --json
252+
```
253+
```json
254+
{
255+
"network": "224.0.0.0",
256+
"prefix": "/4",
257+
"netmask": "240.0.0.0",
258+
"broadcast": "*",
259+
"hostmin": "*",
260+
"hostmax": "*",
261+
"hosts": "*",
262+
"comment": "RFC 5771 Multicast (https://github.com/lancalc/lancalc/blob/main/docs/RFC.md#rfc-5771---multicast-addresses)"
263+
}
264+
```
265+
266+
**GUI Mode:**
267+
- Host fields (Hostmin, Hostmax, Broadcast, Hosts) show "*"
268+
- Status bar displays the special range message instead of version
269+
- No special styling or warnings needed
270+
271+
#### JSON Fields
272+
273+
The JSON output includes the following fields:
274+
275+
- **`comment`**: Description and RFC reference for special ranges (empty for normal unicast addresses)
276+
- **`comment`**: Description and RFC reference for special ranges (empty for normal unicast addresses)
277+
- **`hosts`**: Number of available host addresses in the specified subnet
278+
279+
These fields are always present, making the JSON output format consistent regardless of address type.

docs/CHANGELOG.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# CHANGELOG
2+
3+
All notable changes to LanCalc will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [0.1.8] - 2024-12-19
9+
10+
### Added
11+
- Special IPv4 network detection and handling (loopback, link-local, multicast, unspecified, broadcast)
12+
- Comprehensive tests for special network ranges and edge cases
13+
- RFC documentation links for special networks
14+
15+
### Changed
16+
- Renamed output keys changed in JSON output (network, prefix, netmask, broadcast, hostmin, hostmax, hosts, comment)
17+
- Refactored tests classes to top-level functions
18+
19+
### Fixed
20+
- JSON output filtering: empty comment fields omitted when using -j flag
21+
- Documentation examples updated to match actual API output
22+
23+
### Technical
24+
- Improved test organization and maintainability
25+
- Enhanced GUI error handling with red status for invalid addresses
26+
- Simplified special range display logic

docs/RFC.md

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
# RFC Documentation for Special IPv4 Address Ranges
2+
3+
This document describes the special IPv4 address ranges that LanCalc automatically detects and handles according to RFC specifications.
4+
5+
## Table of Contents
6+
7+
- [RFC 3330 - Loopback Addresses](#rfc-3330---loopback-addresses)
8+
- [RFC 3927 - Link-Local Addresses](#rfc-3927---link-local-addresses)
9+
- [RFC 5771 - Multicast Addresses](#rfc-5771---multicast-addresses)
10+
- [RFC 1122 - Unspecified Addresses](#rfc-1122---unspecified-addresses)
11+
- [RFC 919 - Broadcast Address](#rfc-919---broadcast-address)
12+
13+
---
14+
15+
## RFC 3330 - Loopback Addresses
16+
17+
### Official IETF Document
18+
19+
[RFC 3330 - Special-Use IPv4 Addresses](https://tools.ietf.org/html/rfc3330)
20+
21+
### Description
22+
23+
The loopback address range 127.0.0.0/8 is reserved for communication within the same host. These addresses are not routable on the Internet and are used for internal host-to-host communication, typically for testing and diagnostics.
24+
25+
### Example CLI Output
26+
27+
```bash
28+
$ lancalc 127.0.0.1/8 --json
29+
{
30+
"network": "127.0.0.0",
31+
"prefix": "/8",
32+
"netmask": "255.0.0.0",
33+
"broadcast": "*",
34+
"hostmin": "127.0.0.1",
35+
"hostmax": "127.255.255.254",
36+
"hosts": "16777214",
37+
"comment": "RFC 3330 Loopback (https://github.com/lancalc/lancalc/blob/main/docs/RFC.md#rfc-3330---loopback-addresses)"
38+
}
39+
```
40+
41+
### Notes
42+
43+
- Loopback addresses show actual host range calculations for subnet analysis
44+
- The entire 127.0.0.0/8 range is reserved, not just 127.0.0.1
45+
- Commonly used for localhost communication and application testing
46+
47+
48+
---
49+
50+
## RFC 3927 - Link-Local Addresses
51+
52+
### Official IETF Document
53+
54+
[RFC 3927 - Dynamic Configuration of IPv4 Link-Local Addresses](https://tools.ietf.org/html/rfc3927)
55+
56+
### Description
57+
58+
The link-local address range 169.254.0.0/16 is used for automatic IP address configuration when no DHCP server is available. These addresses are not routable beyond the local network segment and are typically assigned automatically by the operating system.
59+
60+
### Example CLI Output
61+
62+
```bash
63+
$ lancalc 169.254.1.1/16 --json
64+
{
65+
"network": "169.254.0.0",
66+
"prefix": "/16",
67+
"netmask": "255.255.0.0",
68+
"broadcast": "*",
69+
"hostmin": "*",
70+
"hostmax": "*",
71+
"hosts": "*",
72+
"comment": "RFC 3927 Link-local (https://github.com/lancalc/lancalc/blob/main/docs/RFC.md#rfc-3927---link-local-addresses)"
73+
}
74+
```
75+
76+
### Notes
77+
78+
- Host-related fields show "*" because link-local addresses have special automatic assignment behavior
79+
- Commonly seen on Windows systems when DHCP fails (APIPA - Automatic Private IP Addressing)
80+
- Used for local communication only, not routable through gateways
81+
82+
---
83+
84+
## RFC 5771 - Multicast Addresses
85+
86+
### Official IETF Document
87+
88+
[RFC 5771 - IANA Guidelines for IPv4 Multicast Address Assignments](https://tools.ietf.org/html/rfc5771)
89+
90+
### Description
91+
92+
The multicast address range 224.0.0.0/4 (224.0.0.0 - 239.255.255.255) is reserved for IP multicast communication. These addresses are used to send data to multiple hosts simultaneously and are not intended for traditional unicast host addressing.
93+
94+
### Example CLI Output
95+
96+
```bash
97+
$ lancalc 224.0.0.1/4 --json
98+
{
99+
"network": "224.0.0.0",
100+
"prefix": "/4",
101+
"netmask": "240.0.0.0",
102+
"broadcast": "*",
103+
"hostmin": "*",
104+
"hostmax": "*",
105+
"hosts": "*",
106+
"comment": "RFC 5771 Multicast (https://github.com/lancalc/lancalc/blob/main/docs/RFC.md#rfc-5771---multicast-addresses)"
107+
}
108+
```
109+
110+
### Notes
111+
112+
- Host-related fields show "*" because multicast addresses are not used for individual host identification
113+
- Used for protocols like IGMP, streaming media, and group communication
114+
- Different from broadcast as they require explicit group membership
115+
116+
---
117+
118+
## RFC 1122 - Unspecified Addresses
119+
120+
### Official IETF Document
121+
122+
[RFC 1122 - Requirements for Internet Hosts -- Communication Layers](https://tools.ietf.org/html/rfc1122)
123+
124+
### Description
125+
126+
The unspecified address range 0.0.0.0/8 contains addresses that have special meaning in network protocols. The address 0.0.0.0 is used to indicate "this host on this network" and should not be used for regular host addressing. Note that 0.0.0.0/0 (the default route) is treated as normal unicast.
127+
128+
### Example CLI Output
129+
130+
```bash
131+
$ lancalc 0.0.0.1/8 --json
132+
{
133+
"network": "0.0.0.0",
134+
"prefix": "/8",
135+
"netmask": "255.0.0.0",
136+
"broadcast": "*",
137+
"hostmin": "*",
138+
"hostmax": "*",
139+
"hosts": "*",
140+
"comment": "RFC 1122 Unspecified (https://github.com/lancalc/lancalc/blob/main/docs/RFC.md#rfc-1122---unspecified-addresses)"
141+
}
142+
```
143+
144+
### Notes
145+
146+
- Host-related fields show "*" because these addresses have special protocol meanings
147+
- 0.0.0.0 is used in DHCP and routing protocols to indicate "this network"
148+
- The default route 0.0.0.0/0 is treated as normal unicast, not unspecified
149+
150+
---
151+
152+
## RFC 919 - Broadcast Address
153+
154+
### Official IETF Document
155+
156+
[RFC 919 - Broadcasting Internet Datagrams](https://tools.ietf.org/html/rfc919)
157+
158+
### Description
159+
160+
The limited broadcast address 255.255.255.255 is used to send packets to all hosts on the local network segment. This address is never forwarded by routers and is used for network-wide announcements and discovery protocols.
161+
162+
### Example CLI Output
163+
164+
```bash
165+
$ lancalc 255.255.255.255/32 --json
166+
{
167+
"network": "255.255.255.255",
168+
"prefix": "/32",
169+
"netmask": "255.255.255.255",
170+
"broadcast": "*",
171+
"hostmin": "*",
172+
"hostmax": "*",
173+
"hosts": "*",
174+
"comment": "RFC 919 Broadcast (https://github.com/lancalc/lancalc/blob/main/docs/RFC.md#rfc-919---broadcast-address)"
175+
}
176+
```
177+
178+
### Notes
179+
180+
- Host-related fields show "*" because the broadcast address is not used for individual host addressing
181+
- Different from directed broadcast (network broadcast address) as this is the limited broadcast
182+
- Used by protocols like DHCP, ARP, and Wake-on-LAN

lancalc/__init__.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,16 @@
55
LanCalc - A desktop application for calculating network configurations
66
"""
77

8-
__version__ = '0.1.7'
8+
__version__ = '0.1.8'
99
__author__ = 'Aleksandr Pimenov'
1010
__email__ = 'wachawo@gmail.com'
1111

12-
from .main import main, LanCalc
12+
from .main import main
1313

14-
__all__ = ['main', 'LanCalc', '__version__']
14+
# Try to import LanCalc only if GUI is available
15+
try:
16+
from .main import LanCalc # noqa: F401
17+
__all__ = ['main', 'LanCalc', '__version__']
18+
except ImportError:
19+
# GUI not available, only export main function
20+
__all__ = ['main', '__version__']

0 commit comments

Comments
 (0)