https://github.com/clxrityy/gatenet
Python networking toolkit for sockets, TCP/UDP, and HTTP microservices
https://github.com/clxrityy/gatenet
http http-server socket socket-server tcp tcp-client tcp-server udp udp-client udp-server
Last synced: 5 months ago
JSON representation
Python networking toolkit for sockets, TCP/UDP, and HTTP microservices
- Host: GitHub
- URL: https://github.com/clxrityy/gatenet
- Owner: clxrityy
- License: mit
- Created: 2025-05-20T06:49:25.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2025-06-28T22:09:42.000Z (about 1 year ago)
- Last Synced: 2025-06-28T22:27:05.432Z (about 1 year ago)
- Topics: http, http-server, socket, socket-server, tcp, tcp-client, tcp-server, udp, udp-client, udp-server
- Language: Python
- Homepage: https://gatenet.readthedocs.io/en/latest/
- Size: 205 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# gatenet 🛰️
##### BETA
[](https://github.com/clxrityy/gatenet/blob/master/CHANGELOG.md)
[](https://gatenet.readthedocs.io/en/latest/)
| | |
| ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Package** | [](https://pypi.org/project/gatenet/) |
| **Python** | [](https://pypi.org/project/gatenet/) |
| **Tests** | [](https://github.com/clxrityy/gatenet/actions/workflows/test.yml) [](https://codecov.io/gh/clxrityy/gatenet) |
| **License** | [](LICENSE) |
```mermaid
mindmap
root(🛰️)
diagnostics/
dns
geo
ping
port_scan
client/
base
TCP
UDP
http_/
base
client
server
async_client
socket/
base
TCP
UDP
discovery/
MDNS
UPNP
SSH
bluetooth
```
> Python networking toolkit for sockets, UDP, and HTTP microservices — modular and testable.
- [Changelog](https://github.com/clxrityy/gatenet/blob/master/CHANGELOG.md)
- [Installation](#installation)
- [Features](#features)
- [Quickstart](#quickstart)
- [Usage Examples](#usage-examples)
- [Service Discovery](#service-discovery)
- [Diagnostics](#diagnostics)
- [Tests](#tests)
- [Contributing](#contributing)
- [License](#license)
---
## Installation
```zsh
pip install gatenet
```
## Features
- **Modular**: Each component is modular and can be used independently.
- **Testable**: Each component is designed to be testable with unit tests.
- **Service Discovery**: Identify running services (SSH, HTTP, FTP, SMTP, etc.) using banners and ports.
- **Diagnostics**: Tools for traceroute, latency, and bandwidth measurement.
- **Socket Servers & Clients**: TCP, UDP, and HTTP server/client implementations.
- **Async Support**: Asynchronous HTTP client and server.
- **Extensible**: Strategy and chain-of-responsibility patterns for easy extension.
- **Comprehensive Documentation**: With examples and usage guides.
---
## Quickstart
### TCP Client
```python
from gatenet.client.tcp import TCPClient
client = TCPClient(host="127.0.0.1", port=12345)
client.connect()
response = client.send("ping")
print(response)
client.close()
```
### HTTP Server
```python
from gatenet.http.server import HTTPServer
server = HTTPServer(host="0.0.0.0", port=8080)
@server.route("/status", method="GET")
def status_handler(req):
return {"ok": True}
server.serve()
```
---
## Usage Examples
### Service Discovery
Identify a service by port and banner:
```python
from gatenet.discovery.ssh import _identify_service
service = _identify_service(22, "SSH-2.0-OpenSSH_8.9p1")
print(service) # Output: "OpenSSH 8.9p1"
```
Use a specific detector:
```python
from gatenet.discovery.ssh import HTTPDetector
detector = HTTPDetector()
result = detector.detect(80, "apache/2.4.41")
print(result) # Output: "Apache HTTP Server"
```
### Custom Service Detector
```python
from gatenet.discovery.ssh import ServiceDetector
from typing import Optional
class CustomDetector(ServiceDetector):
"""Custom service detector implementation."""
def detect(self, port: int, banner: str) -> Optional[str]:
if 'myapp' in banner:
return "MyCustomApp"
return None
```
---
## Service Discovery
- **SSH, HTTP, FTP, SMTP, and more**: Uses a strategy pattern and chain of responsibility for extensible service detection.
- **Banner and port-based detection**: Extracts service names and versions from banners and well-known ports.
- **Fallback detection**: Always returns a result, even for unknown services.
See [examples/discovery/ssh_discovery.py](examples/discovery/ssh_discovery.py) for more.
---
## Diagnostics
- **Traceroute**: Trace the route to a host.
- **Latency Measurement**: Measure round-trip time to a host.
- **Bandwidth Measurement**: (Planned) Measure throughput to a host.
Example traceroute:
```python
from gatenet.diagnostics.traceroute import traceroute
hops = traceroute("google.com")
for hop in hops:
print(hop)
```
---
## Tests
Run all tests with:
```bash
pytest
```
- Uses `pytest` for all tests.
- Includes unit and integration tests for all modules.
- Use `get_free_port()` from `gatenet.utils.net` in tests to avoid port conflicts.
---
## Contributing
Contributions are welcome! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
- Follow the code style and patterns used in the project.
- Add tests for new features.
- Update documentation as needed.
---
## License
[MIT](LICENSE)