Skip to main content

A Python package for network device discovery and communication

Project description

Nkosi

Python Version License: MIT

Nkosi is a Python package for network device discovery and communication. It provides tools to:

  • Discover devices on your local network using ARP
  • Establish TCP/UDP communication channels
  • Create network servers and clients with minimal code
  • Send and receive messages between devices

Features

  • Device Discovery: Find all devices on your local network using ARP scanning
  • TCP Communication: Full-featured TCP server and client implementations
  • UDP Communication: UDP server and client with broadcast support
  • Easy to Use: Simple API for common networking tasks
  • Cross-platform: Works on Windows, macOS, and Linux

Installation

pip install nkosi

Quick Start

Discovering Devices on Your Network

from nkosi import discover_devices

devices = discover_devices()
for device in devices:
    print(f"IP: {device['ip']}, MAC: {device['mac']}, Hostname: {device['hostname']}")

Creating a TCP Server

from nkosi import TCPServer

def on_message_received(message, client_address):
    print(f"Received from {client_address}: {message}")

server = TCPServer(host='0.0.0.0', port=5000)
server.start(callback=on_message_received)

# Keep the server running
input("Press Enter to stop the server...")
server.stop()

Creating a TCP Client

from nkosi import TCPClient

def on_message_received(message):
    print(f"Received from server: {message}")

client = TCPClient(host='localhost', port=5000)
if client.connect(callback=on_message_received):
    client.send({"type": "greeting", "message": "Hello, server!"})
    
    # Keep the client running
    input("Press Enter to disconnect...")
    client.disconnect()

Creating a UDP Server

from nkosi import UDPServer

def on_message_received(message, client_address):
    print(f"Received from {client_address}: {message}")

server = UDPServer(host='0.0.0.0', port=5001)
server.start(callback=on_message_received)

# Keep the server running
input("Press Enter to stop the server...")
server.stop()

Creating a UDP Client

from nkosi import UDPClient

def on_message_received(message, sender_address):
    print(f"Received from {sender_address}: {message}")

client = UDPClient(host='localhost', port=5001)
if client.start(callback=on_message_received):
    client.send({"type": "greeting", "message": "Hello, server!"})
    
    # Keep the client running
    input("Press Enter to stop the client...")
    client.stop()

Command Line Interface

Nkosi also provides a simple command-line interface for common tasks.

Discover Devices

nkosi-discover

Send a Message

# Send a message to a TCP server
nkosi-send --host localhost --port 5000 --message "Hello, server!" --protocol tcp

# Send a message to a UDP server
nkosi-send --host localhost --port 5001 --message "Hello, server!" --protocol udp

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

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

nkosi-2.1.0.tar.gz (17.8 kB view details)

Uploaded Source

Built Distribution

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

nkosi-2.1.0-py3-none-any.whl (17.1 kB view details)

Uploaded Python 3

File details

Details for the file nkosi-2.1.0.tar.gz.

File metadata

  • Download URL: nkosi-2.1.0.tar.gz
  • Upload date:
  • Size: 17.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.0

File hashes

Hashes for nkosi-2.1.0.tar.gz
Algorithm Hash digest
SHA256 3b6137f184459a5ad3a43f152ab7c92d7000d9c1af306a4a009ad90a6fde3e4c
MD5 1f40e2b00a7eb919014f765372881b10
BLAKE2b-256 8346b5ffe290ab6e4578a5ff504741cb1277b371bb1e6d54d4776c9899191f35

See more details on using hashes here.

File details

Details for the file nkosi-2.1.0-py3-none-any.whl.

File metadata

  • Download URL: nkosi-2.1.0-py3-none-any.whl
  • Upload date:
  • Size: 17.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.0

File hashes

Hashes for nkosi-2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b41f343f2f182c65392795d6f15221cd9c916d754b8ce516b58ee239767519f9
MD5 c30f1d17c694090a382f809f0ffbdefe
BLAKE2b-256 6970f78837889bfa2dfee05f6522a172bb05e1c160d4baa02667e9fe9175a250

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