Skip to content

Commit c307684

Browse files
committed
chore: add project infrastructure and testing setup
1 parent b8f5769 commit c307684

10 files changed

Lines changed: 908 additions & 7 deletions

File tree

.github/workflows/ci.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ main, develop ]
6+
pull_request:
7+
branches: [ main, develop ]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
python-version: ["3.10", "3.11", "3.12"]
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Set up Python ${{ matrix.python-version }}
21+
uses: actions/setup-python@v5
22+
with:
23+
python-version: ${{ matrix.python-version }}
24+
25+
- name: Install package
26+
run: |
27+
python -m pip install --upgrade pip
28+
pip install -e ".[dev]"
29+
30+
- name: Run tests with pytest
31+
run: |
32+
pytest -v --tb=short
33+
34+
- name: Test CLI installation
35+
run: |
36+
netsleuth --help
37+
38+
lint:
39+
runs-on: ubuntu-latest
40+
steps:
41+
- uses: actions/checkout@v4
42+
43+
- name: Set up Python
44+
uses: actions/setup-python@v5
45+
with:
46+
python-version: "3.12"
47+
48+
- name: Install package
49+
run: |
50+
python -m pip install --upgrade pip
51+
pip install -e .
52+
53+
- name: Check package imports
54+
run: |
55+
python -c "from NetSleuth import resolve_host, scan_ports, parse_ports; print('Imports OK')"

NetSleuth/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
This package provides tools for network port scanning and host discovery.
55
"""
66

7-
__version__ = "0.1.0"
7+
__version__ = "0.2.0"
88

99
from .models import ScanResult
1010
from .scanner import resolve_host, scan_port, scan_ports
1111
from .ports import parse_ports
1212
from .banner import grab_banner
1313
from .reporter import results_to_dict, write_json, write_ndjson
14+
from .utils import is_valid_port, format_duration, calculate_scan_estimate
1415

1516
__all__ = [
1617
"ScanResult",
@@ -22,4 +23,7 @@
2223
"results_to_dict",
2324
"write_json",
2425
"write_ndjson",
26+
"is_valid_port",
27+
"format_duration",
28+
"calculate_scan_estimate",
2529
]

NetSleuth/reporter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def results_to_dict(target_host: str, target_ip: str, timeout: float, workers: i
1919
"""
2020
return {
2121
"tool": "NetSleuth",
22-
"version": "0.1.0",
22+
"version": "0.2.0",
2323
"timestamp": datetime.now(timezone.utc).isoformat(),
2424
"target": {
2525
"host": target_host,

NetSleuth/utils.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
def is_valid_port(port: int) -> bool:
2+
"""
3+
Check if a port number is within the valid range (1-65535).
4+
5+
Args:
6+
port: Port number to validate.
7+
8+
Returns:
9+
True if the port is valid, False otherwise.
10+
"""
11+
return 1 <= port <= 65535
12+
13+
14+
def format_duration(seconds: float) -> str:
15+
"""
16+
Format a duration in seconds to a human-readable string.
17+
18+
Args:
19+
seconds: Duration in seconds.
20+
21+
Returns:
22+
Formatted string (e.g., "1.5s", "2m 30s", "1h 5m").
23+
"""
24+
if seconds < 60:
25+
return f"{seconds:.1f}s"
26+
elif seconds < 3600:
27+
minutes = int(seconds // 60)
28+
secs = int(seconds % 60)
29+
return f"{minutes}m {secs}s"
30+
else:
31+
hours = int(seconds // 3600)
32+
minutes = int((seconds % 3600) // 60)
33+
return f"{hours}h {minutes}m"
34+
35+
36+
def calculate_scan_estimate(num_ports: int, timeout: float, workers: int) -> float:
37+
"""
38+
Estimate the total scan time based on parameters.
39+
40+
Args:
41+
num_ports: Number of ports to scan.
42+
timeout: Timeout per connection in seconds.
43+
workers: Number of concurrent workers.
44+
45+
Returns:
46+
Estimated scan time in seconds.
47+
"""
48+
if workers <= 0:
49+
workers = 1
50+
51+
# Rough estimate: time per batch * number of batches
52+
# Add small overhead for threading
53+
batches = (num_ports + workers - 1) // workers
54+
return batches * timeout * 1.1 # 10% overhead

0 commit comments

Comments
 (0)