Pydhcp
Simple Python DHCP Library. DHCP Packet-Parsing/Client/Server
Install / Use
/learn @imgurbot12/PydhcpREADME
pydhcp
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
)
Related Skills
node-connect
350.8kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
claude-opus-4-5-migration
110.4kMigrate prompts and code from Claude Sonnet 4.0, Sonnet 4.5, or Opus 4.1 to Opus 4.5
frontend-design
110.4kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
model-usage
350.8kUse CodexBar CLI local cost usage to summarize per-model usage for Codex or Claude, including the current (most recent) model or a full model breakdown. Trigger when asked for model-level usage/cost data from codexbar, or when you need a scriptable per-model summary from codexbar cost JSON.
