Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ exclude =
__pycache__,
*.egg-info,
build,
dist
dist,
.backup,
14 changes: 5 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,17 @@ jobs:
flake8 lancalc/ --count --select=E9,F63,F7,F82 --show-source --statistics
flake8 lancalc/ --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics

- name: Run core tests
run: |
python -m pytest test_lancalc.py -v

- name: Run GUI tests (Linux)
- name: Run tests (Linux)
if: matrix.os == 'ubuntu-latest'
run: |
xvfb-run -a python -m pytest test_lancalc.py -v
- name: Run GUI tests (macOS)

- name: Run tests (macOS)
if: matrix.os == 'macos-latest'
run: |
python -m pytest test_lancalc.py -v
- name: Run GUI tests (Windows)

- name: Run tests (Windows)
if: matrix.os == 'windows-latest'
run: |
python -m pytest test_lancalc.py -v
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: publish
name: Publish
on:
push:
tags:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ venv/
ENV/
env.bak/
venv.bak/
.backup

# Spyder project settings
.spyderproject
Expand Down
172 changes: 159 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

LanCalc is a desktop application built with PyQt5, designed to calculate network configurations for Windows, macOS, and Linux systems.

![image](https://github.com/user-attachments/assets/be7655cc-9348-4d7c-bb25-a650e00cc422)
![image](https://github.com/user-attachments/assets/a7d1779f-d138-4819-84c6-4df876efc292)

[Download](https://github.com/lancalc/lancalc/releases)

Expand All @@ -18,19 +18,44 @@ Support IPv4 address formats, subnet masks and prefixes. This tool is particular

### Installation

**Install LanCalc Stable version:**
Python 3.9+ is required.

- Default (with GUI):

```bash
pip3 install lancalc
```

**Or install LanCalc from GitHub:**
- CLI-only / headless (avoid installing PyQt5):

```bash
# Install package without dependencies, then only required CLI deps
pip3 install --no-deps lancalc
pip3 install -r requirements.txt
```

- Install without GUI dependencies:

```bash
# Install with nogui extras (excludes PyQt5)
pip3 install 'lancalc[nogui]'
```

- Install from GitHub:

```bash
pip3 install git+https://github.com/lancalc/lancalc.git
# With GUI (default)
pip3 install 'git+https://github.com/lancalc/lancalc.git'

# CLI-only / headless
pip3 install --no-deps 'git+https://github.com/lancalc/lancalc.git'
pip3 install -r requirements.txt

# Without GUI dependencies
pip3 install 'git+https://github.com/lancalc/lancalc.git#egg=lancalc[nogui]'
```

Install PIP
If pip is missing:

```bash
curl https://bootstrap.pypa.io/get-pip.py -o /tmp/get-pip.py
Expand All @@ -50,16 +75,22 @@ echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
```

Notes:
- On Linux, PyQt5 may require system Qt libraries (xcb plugin). If GUI fails to start, ensure a desktop environment is available and try installing system packages (e.g. Debian/Ubuntu: `sudo apt install python3-pyqt5`), or use the CLI-only steps above.
- In CI/headless environments, prefer the CLI-only steps above to skip GUI dependencies.

## Running the Application

### GUI Mode

After installation, launch the application with the command:
After installation (default with GUI), launch the application with the command:

```bash
lancalc
```

LanCalc auto-detects the environment. If GUI dependencies are unavailable or you are in a headless session, the launcher falls back to CLI help. In such cases, use the CLI examples below.

### CLI Mode

LanCalc also supports command-line interface for automation and scripting:
Expand All @@ -78,6 +109,12 @@ lancalc 192.168.1.100/31 # Point-to-point network
lancalc 192.168.1.1/32 # Single host
```

You can also run via module:

```bash
python3 -m lancalc 192.168.1.1/24 --json
```

### Output Format

**Text mode** (default):
Expand Down Expand Up @@ -117,21 +154,39 @@ That's it! The application will start and automatically detect your current netw

### Prerequisites

Python 3.9+ is required.
Python 3.9+ is required. GUI development requires PyQt5 (installed by default).

For production use (CLI only):
- Production (CLI only):
```bash
pip3 install -r requirements.txt
```

For GUI support:
- Editable install with GUI (default):
```bash
pip3 install -e .[gui]
pip3 install -e .
```

For development:
- Editable install without GUI:
```bash
pip3 install -e .[dev,gui]
pip3 install --no-deps -e .
pip3 install -r requirements.txt
```

- Full dev setup (with GUI):
```bash
pip3 install -e '.[dev]'
```

- Dev without GUI:
```bash
pip3 install --no-deps -e .
pip3 install -r requirements.txt
pip3 install pytest pytest-qt pre-commit flake8
```

- Reinstall
```bash
pip3 install -e . --force-reinstall
```

### Installation for Development
Expand All @@ -145,7 +200,11 @@ git clone https://github.com/lancalc/lancalc.git
### Running from Source

```bash
# GUI (requires PyQt5)
python3 lancalc/main.py

# CLI
python3 -m lancalc 192.168.1.1/24
```

### Development Tools
Expand Down Expand Up @@ -272,8 +331,95 @@ lancalc 224.0.0.1/4 --json

The JSON output includes the following fields:

- **`comment`**: Description and RFC reference for special ranges (empty for normal unicast addresses)
- **`comment`**: Description and RFC reference for special ranges (empty for normal unicast addresses)
- **`hosts`**: Number of available host addresses in the specified subnet

These fields are always present, making the JSON output format consistent regardless of address type.

## Usage

### Command Line Interface

```bash
# Basic subnet calculation
lancalc 192.168.1.1/24

# JSON output
lancalc 192.168.1.1/24 --json

# Show internal/private IP address
lancalc --internal
lancalc -i

# Show external/public IP address
lancalc --external
lancalc -e

# Use multiple info flags simultaneously
lancalc -i -e
lancalc -i -e --json

# Show version
lancalc --version
```

### Examples

**Basic calculation:**
```bash
$ lancalc 192.168.1.1/24
Network: 192.168.1.0
Prefix: /24
Netmask: 255.255.255.0
Broadcast: 192.168.1.255
Hostmin: 192.168.1.1
Hostmax: 192.168.1.254
Hosts: 254
```

**JSON output:**
```bash
$ lancalc 192.168.1.1/24 --json
{
"network": "192.168.1.0",
"prefix": "/24",
"netmask": "255.255.255.0",
"broadcast": "192.168.1.255",
"hostmin": "192.168.1.1",
"hostmax": "192.168.1.254",
"hosts": "254"
}
```

**Interface information:**
```bash
$ lancalc -i
Address: 10.16.69.146
Prefix: /24

$ lancalc -i --json
{"address": "10.16.69.146", "prefix": "/24"}
```

**External IP detection:**
```bash
$ lancalc -e
External IP: 216.66.18.3

$ lancalc -e --json
{"external_ip": "216.66.18.3"}
```

**Multiple info flags:**
```bash
$ lancalc -i -e
Address: 10.16.69.146
Prefix: /24

External IP: 216.66.18.3

$ lancalc -i -e --json
{"address": "10.16.69.146", "prefix": "/24"}

{"external_ip": "216.66.18.3"}
```
23 changes: 23 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,29 @@ All notable changes to LanCalc will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.1.9] - 2024-12-19

### Added
- **External IP detection**: New `-e/--external` CLI flag to retrieve external/public IP address via `https://ifconfig.me/`
- **Simultaneous CLI flags**: Support for using multiple info flags simultaneously (e.g., `-i -e`)
- **Modular architecture**: Created `adapters.py` for external system interactions
- **Clean separation**: Moved network interface detection and external IP retrieval to `adapters.py`
- **Enhanced error handling**: Better validation and error messages for external IP retrieval
- **nogui extras**: New optional dependency group for CLI-only installations without PyQt5
- **Adaptive launcher**: Main entry point automatically detects environment and chooses CLI/GUI mode
- **Better error handling**: Improved fallback mechanisms when GUI is unavailable

### Changed
- **Architecture refactoring**: Simplified project structure with main.py as core CLI and gui.py as optional GUI module
- **Modular design**: Separated CLI and GUI functionality into distinct modules for better maintainability
- **Optional GUI**: GUI can now be installed separately or excluded entirely via nogui extras
- **Clean imports**: Replaced complex import fallbacks with clean absolute package imports

### Technical
- **Simplified structure**: Removed cli.py, core.py modules in favor of consolidated main.py
- **Import optimization**: Clean absolute imports throughout the codebase
- **Entry point fixes**: Corrected pyproject.toml entry point to use main module

## [0.1.8] - 2024-12-19

### Added
Expand Down
35 changes: 27 additions & 8 deletions lancalc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,38 @@
# -*- coding: utf-8 -*-

"""
LanCalc - A desktop application for calculating network configurations
LanCalc - IPv4 subnet calculator with GUI and CLI interfaces.

A cross-platform tool for calculating IPv4 network parameters including
network address, broadcast address, host range, and special IPv4 range detection.
"""

__version__ = '0.1.8'
__version__ = "0.1.9"
__author__ = 'Aleksandr Pimenov'
__email__ = 'wachawo@gmail.com'

from .main import main
# Import modules
from . import core
from . import cli
from . import gui
from . import main
from . import adapters

# Try to import LanCalc only if GUI is available
# Export LanCalc for tests
try:
from .main import LanCalc # noqa: F401
__all__ = ['main', 'LanCalc', '__version__']
from .gui import LanCalcGUI
LanCalc = LanCalcGUI
except ImportError:
# GUI not available, only export main function
__all__ = ['main', '__version__']
LanCalc = None

__all__ = [
"__version__",
"__author__",
"__email__",
"core",
"cli",
"gui",
"main",
"adapters",
"LanCalc",
]
8 changes: 8 additions & 0 deletions lancalc/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys
from . import main

if __name__ == "__main__":
sys.exit(main.main())
Loading
Loading