Skip to main content

pydhcp

PyPI version Python versions License: MIT Made with Love

Simple Python DHCP Library. DHCP Packet-Parsing/Client/Server

Installation

pip install pydhcp3

DHCPv4 Examples

Packet Parsing

from pydhcp.v4 import Message

hex = \
    '0101060000003d1d0000000000000000000000000000000000000000000b8201fc4200' +\
    '0000000000000000000000000000000000000000000000000000000000000000000000' +\
    '0000000000000000000000000000000000000000000000000000000000000000000000' +\
    '0000000000000000000000000000000000000000000000000000000000000000000000' +\
    '0000000000000000000000000000000000000000000000000000000000000000000000' +\
    '0000000000000000000000000000000000000000000000000000000000000000000000' +\
    '0000000000000000000000000000000000000000000000000000638253633501013d07' +\
    '01000b8201fc4232040000000037040103062aff00000000000000'

raw     = bytes.fromhex(hex)
message = Message.unpack(raw)
print(message)

Client

from pydhcp.v4 import Message
from pydhcp.v4.client import Client, new_message_id

mac    = 'aa:bb:cc:dd:ee:ff'
client = Client(interface=None)

# send crafted messages
id       = new_message_id()
hwaddr   = bytes.fromhex(mac.replace(':', ''))
request  = Message.discover(id, hwaddr)
response = client.request(request)
print(response)

# or simplify the standard network assignment request process
record = client.request_assignment(mac)
print(record)

Server

import logging
from ipaddress import IPv4Address, IPv4Network

from pyserve import listen_udp_threaded

from pydhcp.v4.server import Server
from pydhcp.v4.server.backend import MemoryBackend, CacheBackend

# prepare simple memory backend as base provider
backend = MemoryBackend(
    network=IPv4Network('192.168.1.0/24'),
    gateway=IPv4Address('192.168.1.1'),
    dns=[IPv4Address('8.8.8.8'), IPv4Address('8.8.4.4')],
)

# wrap backend w/ cache (not really useful here but for non-memory backends)
backend = CacheBackend(backend)

# configure optional logger for server implementaion
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger('myserver')
logger.setLevel(logging.INFO)

# launch server and run forever using pyserve
listen_udp_threaded(
    address=('0.0.0.0', 67),
    factory=Server,
    allow_broadcast=True,
    backend=backend,
    logger=logger,
    server_id=IPv4Address('192.168.1.1') # dhcp server address
)

Metadata

Release files for pydhcp3 0.0.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pydhcp3 0.0.6
File Size Uploaded Provenance Actions
pydhcp3-0.0.6.tar.gz 24.5 kB Without provenance Details for pydhcp3-0.0.6.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pydhcp3 0.0.6
File Interpreter ABI Platform Actions
pydhcp3-0.0.6-py3-none-any.whl Python 3 none any Details for pydhcp3-0.0.6-py3-none-any.whl

Total release size: 54.7 kB

Release files / pydhcp3-0.0.6.tar.gz

Download URL pydhcp3-0.0.6.tar.gz
Size 24.5 kB
Tags Source
SHA-256 checksum
How to use checksums
40bfcafe7b2e2eb08231b0591bfaa55af65be8185454d6a223705565176e4190
BLAKE2b-256 checksum
How to use checksums
ac69af25aabc146ee88232428db53c3758ef8778ca8fa181a384b71059f97547
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.8.20

Release files / pydhcp3-0.0.6-py3-none-any.whl

Download URL pydhcp3-0.0.6-py3-none-any.whl
Size 30.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9ae118b340828a675af18beb31ba2f14459e3abddb10ddaad3c205d1becbae53
BLAKE2b-256 checksum
How to use checksums
cf4bfa2ee4a9a1caade1a979bfb6eefc2439ec8932e92cb923f0ad7c829d78f1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.8.20

Security for pydhcp3 0.0.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page