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.1.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.1-py3-none-any.whl (17.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: nkosi-2.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 a3770e17cd2f9087564665b3b3cba37a3adbf128061b13fa606a6aaea461a8c6
MD5 cb920ce51fe76e74bb88571ec4893bb8
BLAKE2b-256 7dc23ef22ca1fe014d425964785db38f739548dfbf78e556f6300936c1e1f40b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: nkosi-2.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 89d708880093e2d6d5991911629e14444480592f3105476684fd8a1291a78c56
MD5 0c72a2b37d330afffbdd12a5833215e6
BLAKE2b-256 7e4b9dca05da62d08e55468949dd589c35e87195f75a7dadd7127d95baf6cf17

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