Skip to main content

Python library for gateways, networks, and devices.

Project description

gatenet 🛰️

BETA

Changelog Static Badge

Package PyPI
Python Python
Tests CI codecov
License License
mindmap
  root(🛰️)
    diagnostics/
      dns
      geo
      ping
      port_scan
      bandwidth
    client/
      base
        TCP
        UDP
    http_/
        base
            client
            server
            async_client
    socket/
        base
            TCP
            UDP
    discovery/
        MDNS
        UPNP
        SSH
        bluetooth

Gatenet is a batteries-included Python networking toolkit for diagnostics, service discovery, and building robust socket, UDP, and HTTP microservices.

  • Diagnostics: Traceroute, ping/latency, bandwidth, port scanning, geo IP, and more.
  • Service Discovery: Identify running services (SSH, HTTP, FTP, SMTP, mDNS, SSDP, Bluetooth, etc.) using banners, ports, and extensible detectors.
  • Socket & HTTP: Modular TCP/UDP/HTTP servers and clients, with async support.
  • Extensible: Strategy and chain-of-responsibility patterns for easy extension and custom detection.
  • Comprehensive tests and documentation.

Gatenet is designed for developers who need reliable, extensible, and well-tested networking tools for diagnostics, automation, and microservice development.


Installation

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

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

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:

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:

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

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 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:

from gatenet.diagnostics.traceroute import traceroute

hops = traceroute("google.com")
for hop in hops:
    print(hop)

Tests

Run all tests with:

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 for guidelines.

  • Follow the code style and patterns used in the project.
  • Add tests for new features.
  • Update documentation as needed.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gatenet-0.8.4.tar.gz (23.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gatenet-0.8.4-py3-none-any.whl (13.6 kB view details)

Uploaded Python 3

File details

Details for the file gatenet-0.8.4.tar.gz.

File metadata

  • Download URL: gatenet-0.8.4.tar.gz
  • Upload date:
  • Size: 23.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.0

File hashes

Hashes for gatenet-0.8.4.tar.gz
Algorithm Hash digest
SHA256 94d44cc086c18535f50bf4d10025ed37394e05942139551157507939a99d80c8
MD5 54584bdcfa0c9e7d4d17de53fdf5dd8a
BLAKE2b-256 0b43d47e87b4fddeca321205d0489eea7ba8f7eb346b70f542880cd42362477a

See more details on using hashes here.

File details

Details for the file gatenet-0.8.4-py3-none-any.whl.

File metadata

  • Download URL: gatenet-0.8.4-py3-none-any.whl
  • Upload date:
  • Size: 13.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.0

File hashes

Hashes for gatenet-0.8.4-py3-none-any.whl
Algorithm Hash digest
SHA256 41cac16b6ef9925f705b978e92b0a9f6842729af5909a3ba6986ca7301cf6657
MD5 76cc181bbf4c91c3a9a73ff61c35ffbc
BLAKE2b-256 3e86d5c722d6d3b573207d86e7bcb52db0212c75b20981a04160996baf0f6793

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page