netrax 0.1.0__py3-none-any.whl
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.
Potentially problematic release.
This version of netrax might be problematic. Click here for more details.
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: netrax
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Async Python wrapper for Nmap
|
|
5
|
+
Project-URL: Homepage, https://github.com/code-1py/NetraX
|
|
6
|
+
Project-URL: Repository, https://github.com/code-1py/NetraX
|
|
7
|
+
Project-URL: Issues, https://github.com/code-1py/NetraX/issues
|
|
8
|
+
License: MIT License
|
|
9
|
+
|
|
10
|
+
Copyright (c) 2025 Bhavya Malhotra
|
|
11
|
+
|
|
12
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
13
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
14
|
+
in the Software without restriction, including without limitation the rights
|
|
15
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
16
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
17
|
+
furnished to do so, subject to the following conditions:
|
|
18
|
+
|
|
19
|
+
The above copyright notice and this permission notice shall be included in all
|
|
20
|
+
copies or substantial portions of the Software.
|
|
21
|
+
|
|
22
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
23
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
24
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
25
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
26
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
27
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
28
|
+
SOFTWARE.
|
|
29
|
+
License-File: LICENSE
|
|
30
|
+
Keywords: async,asyncio,network,nmap,port-scanner,scanner,security
|
|
31
|
+
Classifier: Framework :: AsyncIO
|
|
32
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
33
|
+
Classifier: Operating System :: OS Independent
|
|
34
|
+
Classifier: Programming Language :: Python :: 3
|
|
35
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
36
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
37
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
38
|
+
Classifier: Topic :: Security
|
|
39
|
+
Classifier: Topic :: System :: Networking
|
|
40
|
+
Classifier: Typing :: Typed
|
|
41
|
+
Requires-Python: >=3.11
|
|
42
|
+
Description-Content-Type: text/markdown
|
|
43
|
+
|
|
44
|
+
# netrax
|
|
45
|
+
|
|
46
|
+
**Async Python wrapper for Nmap** — run network scans, parse results, and integrate with your tools using clean async/await syntax.
|
|
47
|
+
|
|
48
|
+
[](https://pypi.org/project/netrax/)
|
|
49
|
+
[](https://pypi.org/project/netrax/)
|
|
50
|
+
[](LICENSE)
|
|
51
|
+
|
|
52
|
+
> **Note:** netrax requires [Nmap](https://nmap.org) to be installed on your system.
|
|
53
|
+
> Nmap is a separate open-source tool distributed under the
|
|
54
|
+
> [Nmap Public Source License](https://svn.nmap.org/nmap/LICENSE). netrax does not
|
|
55
|
+
> bundle or redistribute Nmap — it invokes it as an external process.
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## Features
|
|
60
|
+
|
|
61
|
+
- **Fully async** — built on `asyncio`, no blocking calls
|
|
62
|
+
- **7 built-in scan types** — service, SYN, UDP, OS, aggressive, ping, and fully custom
|
|
63
|
+
- **Typed dataclass models** — structured access to every field in the Nmap XML output
|
|
64
|
+
- **Rich exception hierarchy** — granular error handling for timeouts, bad targets, missing Nmap, and more
|
|
65
|
+
- **Configurable timeouts** — global defaults or per-scan overrides
|
|
66
|
+
- **Admin privilege check** — fails fast with a clear error if root/administrator access is missing
|
|
67
|
+
- **JSON and dict export** — `report.to_dict()` and `report.to_json()` built in
|
|
68
|
+
- **Zero dependencies** — uses only the Python standard library
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
## Requirements
|
|
73
|
+
|
|
74
|
+
- Python 3.11+
|
|
75
|
+
- [Nmap](https://nmap.org/download.html) installed and available in `PATH`
|
|
76
|
+
- Administrator / root privileges (required by Nmap for most scan types)
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## Installation
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
pip install netrax
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Then make sure Nmap is installed on your system:
|
|
87
|
+
|
|
88
|
+
| OS | Command |
|
|
89
|
+
|---|---|
|
|
90
|
+
| Ubuntu / Debian | `sudo apt install nmap` |
|
|
91
|
+
| Fedora / RHEL | `sudo dnf install nmap` |
|
|
92
|
+
| macOS | `brew install nmap` |
|
|
93
|
+
| Windows | Download from [nmap.org](https://nmap.org/download.html) |
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
## Quick Start
|
|
98
|
+
|
|
99
|
+
```python
|
|
100
|
+
import asyncio
|
|
101
|
+
import netrax
|
|
102
|
+
|
|
103
|
+
async def main():
|
|
104
|
+
scanner = netrax.Scanner()
|
|
105
|
+
|
|
106
|
+
# Service and version detection
|
|
107
|
+
report = await scanner.service_scan("192.168.1.1")
|
|
108
|
+
|
|
109
|
+
for host in report.hosts:
|
|
110
|
+
for addr in host.address:
|
|
111
|
+
print(f"Host: {addr.addr}")
|
|
112
|
+
for port in host.ports:
|
|
113
|
+
print(port.portid, port.state.state, port.services.name)
|
|
114
|
+
|
|
115
|
+
asyncio.run(main())
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
## Scan Types
|
|
121
|
+
|
|
122
|
+
All scan methods return a `ScanReport` object.
|
|
123
|
+
|
|
124
|
+
| Method | Nmap Flag | Description |
|
|
125
|
+
|---|---|---|
|
|
126
|
+
| `service_scan(target)` | `-sV` | Service and version detection |
|
|
127
|
+
| `syn_scan(target)` | `-sS` | TCP SYN scan (fast, stealthy) |
|
|
128
|
+
| `udp_scan(target)` | `-sU` | UDP port scan |
|
|
129
|
+
| `os_scan(target)` | `-O` | Operating system detection |
|
|
130
|
+
| `aggressive_scan(target)` | `-A` | OS + version + scripts + traceroute |
|
|
131
|
+
| `ping_scan(target)` | `-sn` | Host discovery only (no port scan) |
|
|
132
|
+
| `scan(target, *arguments)` | custom | Pass any Nmap flags directly |
|
|
133
|
+
|
|
134
|
+
### Custom scan example
|
|
135
|
+
|
|
136
|
+
```python
|
|
137
|
+
report = await scanner.scan(
|
|
138
|
+
"10.0.0.0/24",
|
|
139
|
+
"-sV",
|
|
140
|
+
"-O",
|
|
141
|
+
"-T4",
|
|
142
|
+
"--open",
|
|
143
|
+
)
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
---
|
|
147
|
+
|
|
148
|
+
## Timeouts
|
|
149
|
+
|
|
150
|
+
Every scan method accepts an optional `timeout` parameter (seconds). If omitted, the global default is used.
|
|
151
|
+
|
|
152
|
+
```python
|
|
153
|
+
# Per-scan timeout
|
|
154
|
+
report = await scanner.aggressive_scan("192.168.1.1", timeout=300)
|
|
155
|
+
|
|
156
|
+
# Change the global default
|
|
157
|
+
from netrax.config import timeouts
|
|
158
|
+
timeouts.DEFAULT_SCAN_TIMEOUT = 120
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
> **Note:** Slow timing templates (`-T0`, `-T1`, `-T2`) will trigger an automatic warning
|
|
162
|
+
> suggesting you increase the timeout.
|
|
163
|
+
|
|
164
|
+
---
|
|
165
|
+
|
|
166
|
+
## Working with Results
|
|
167
|
+
|
|
168
|
+
`ScanReport` is a fully typed dataclass. You can access every field directly, or export to dict/JSON.
|
|
169
|
+
|
|
170
|
+
```python
|
|
171
|
+
report = await scanner.service_scan("192.168.1.1")
|
|
172
|
+
|
|
173
|
+
# Access structured data
|
|
174
|
+
for host in report.hosts:
|
|
175
|
+
for addr in host.address:
|
|
176
|
+
print(f"IP: {addr.addr} Type: {addr.addrtype}")
|
|
177
|
+
|
|
178
|
+
for port in host.ports:
|
|
179
|
+
svc = port.services
|
|
180
|
+
print(f"Port {port.portid}/{port.protocol} — {port.state.state}")
|
|
181
|
+
if svc:
|
|
182
|
+
print(f" Service: {svc.name} {svc.product} {svc.version}")
|
|
183
|
+
|
|
184
|
+
# Export
|
|
185
|
+
data = report.to_dict()
|
|
186
|
+
json_str = report.to_json(indent=4)
|
|
187
|
+
raw_xml = report.raw_xml
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### Data model overview
|
|
191
|
+
|
|
192
|
+
```
|
|
193
|
+
ScanReport
|
|
194
|
+
├── nmaprun (NmapRun) — scanner metadata, args, version
|
|
195
|
+
├── scaninfo (ScanInfo) — scan type, protocol, service count
|
|
196
|
+
├── verbose_level (int)
|
|
197
|
+
├── debugging_level (int)
|
|
198
|
+
├── raw_xml (str) — raw Nmap XML output
|
|
199
|
+
└── hosts (list[Host])
|
|
200
|
+
├── starttime / endtime
|
|
201
|
+
├── address (list[Address]) — IP and MAC addresses
|
|
202
|
+
├── hostnames (list[HostName])
|
|
203
|
+
├── extraports (ExtraPorts)
|
|
204
|
+
├── times (Times) — RTT statistics
|
|
205
|
+
└── ports (list[Port])
|
|
206
|
+
├── portid / protocol
|
|
207
|
+
├── state (State) — open/closed/filtered + reason
|
|
208
|
+
└── services (Service) — name, product, version, tunnel
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
---
|
|
212
|
+
|
|
213
|
+
## Exception Handling
|
|
214
|
+
|
|
215
|
+
```python
|
|
216
|
+
from netrax.exceptions import (
|
|
217
|
+
AdminRequiredError,
|
|
218
|
+
NmapNotFoundError,
|
|
219
|
+
NmapExecutionError,
|
|
220
|
+
ScanTimeoutError,
|
|
221
|
+
InvalidTargetError,
|
|
222
|
+
XmlParseError,
|
|
223
|
+
)
|
|
224
|
+
|
|
225
|
+
try:
|
|
226
|
+
report = await scanner.service_scan("192.168.1.1")
|
|
227
|
+
except AdminRequiredError:
|
|
228
|
+
print("Run as root / administrator.")
|
|
229
|
+
except NmapNotFoundError:
|
|
230
|
+
print("Nmap is not installed or not in PATH.")
|
|
231
|
+
except ScanTimeoutError as e:
|
|
232
|
+
print(f"Scan timed out after {e.timeout}s.")
|
|
233
|
+
except NmapExecutionError as e:
|
|
234
|
+
print(f"Nmap error (exit {e.returncode}): {e.stderr}")
|
|
235
|
+
except XmlParseError:
|
|
236
|
+
print("Could not parse Nmap XML output.")
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
### Exception hierarchy
|
|
240
|
+
|
|
241
|
+
```
|
|
242
|
+
NetraxError (base)
|
|
243
|
+
├── AdminRequiredError
|
|
244
|
+
├── NmapNotFoundError
|
|
245
|
+
├── NmapExecutionError
|
|
246
|
+
├── ScanTimeoutError
|
|
247
|
+
├── ProcessTimeoutError
|
|
248
|
+
├── InvalidTargetError
|
|
249
|
+
├── InvalidScanProfileError
|
|
250
|
+
├── XmlParseError
|
|
251
|
+
├── AIProviderError
|
|
252
|
+
└── ReportGenerationError
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
---
|
|
256
|
+
|
|
257
|
+
## API Reference
|
|
258
|
+
|
|
259
|
+
### `Scanner`
|
|
260
|
+
|
|
261
|
+
```python
|
|
262
|
+
scanner = Scanner()
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
Instantiating `Scanner` checks for root/administrator privileges immediately.
|
|
266
|
+
All scan methods are coroutines and must be awaited.
|
|
267
|
+
|
|
268
|
+
#### `scan(target, *arguments, timeout=None) → ScanReport`
|
|
269
|
+
Run Nmap with arbitrary arguments.
|
|
270
|
+
|
|
271
|
+
#### `service_scan(target, timeout=None) → ScanReport`
|
|
272
|
+
Service and version detection (`-sV`).
|
|
273
|
+
|
|
274
|
+
#### `syn_scan(target, timeout=None) → ScanReport`
|
|
275
|
+
TCP SYN scan (`-sS`).
|
|
276
|
+
|
|
277
|
+
#### `udp_scan(target, timeout=None) → ScanReport`
|
|
278
|
+
UDP scan (`-sU`).
|
|
279
|
+
|
|
280
|
+
#### `os_scan(target, timeout=None) → ScanReport`
|
|
281
|
+
OS detection (`-O`).
|
|
282
|
+
|
|
283
|
+
#### `aggressive_scan(target, timeout=None) → ScanReport`
|
|
284
|
+
Aggressive scan (`-A`): OS + version + scripts + traceroute.
|
|
285
|
+
|
|
286
|
+
#### `ping_scan(target, timeout=None) → ScanReport`
|
|
287
|
+
Host discovery only (`-sn`).
|
|
288
|
+
|
|
289
|
+
---
|
|
290
|
+
|
|
291
|
+
### `ScanReport`
|
|
292
|
+
|
|
293
|
+
| Method | Returns | Description |
|
|
294
|
+
|---|---|---|
|
|
295
|
+
| `to_dict()` | `dict` | Full report as a Python dictionary |
|
|
296
|
+
| `to_json(indent=None)` | `str` | Full report as a JSON string |
|
|
297
|
+
|
|
298
|
+
---
|
|
299
|
+
|
|
300
|
+
## Configuration
|
|
301
|
+
|
|
302
|
+
```python
|
|
303
|
+
from netrax.config import timeouts
|
|
304
|
+
|
|
305
|
+
timeouts.DEFAULT_SCAN_TIMEOUT = 120 # seconds (default: 60)
|
|
306
|
+
timeouts.NMAP_LOCATE_TIMEOUT = 5 # seconds (default: 3)
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
---
|
|
310
|
+
|
|
311
|
+
## Legal
|
|
312
|
+
|
|
313
|
+
netrax is released under the [MIT License](LICENSE).
|
|
314
|
+
|
|
315
|
+
This project invokes [Nmap](https://nmap.org) as an external subprocess.
|
|
316
|
+
Nmap is not bundled with netrax and is distributed under its own
|
|
317
|
+
[Nmap Public Source License](https://svn.nmap.org/nmap/LICENSE).
|
|
318
|
+
Users are responsible for complying with Nmap's license and all applicable
|
|
319
|
+
laws when performing network scans. Only scan networks and systems you own
|
|
320
|
+
or have explicit permission to scan.
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
netrax-0.1.0.dist-info/METADATA,sha256=eHW58_KtsqscK5jedUWkxIV1TYOctReRaMJ1igaSa1Y,9790
|
|
2
|
+
netrax-0.1.0.dist-info/WHEEL,sha256=mffPy8wBnZQn2VnJUU5jE99KsxaSfiyMHV9Yt0aLVxs,87
|
|
3
|
+
netrax-0.1.0.dist-info/licenses/LICENSE,sha256=EzZ2LSgtPtI_wICk8j6nYX53FSiYRoXRuGRwyEGwmjw,1091
|
|
4
|
+
netrax-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Bhavya Malhotra
|
|
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.
|