Metadata-Version: 2.1
Name: pydhcp3
Version: 0.0.6
Summary: Simple Python DHCP Library. DHCP Packet-Parsing/Client/Server
Author-email: Andrew C Scott <imgurbot12@gmail.com>
License: The MIT License (MIT)
        
        Copyright (c) 2025 Andrew C Scott
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
        
Project-URL: Repository, https://github.com/imgurbot12/pydhcp
Keywords: dhcp,client,server,parser
Classifier: Typing :: Typed
Classifier: License :: OSI Approved :: MIT License
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pypool3>=0.0.2
Requires-Dist: pyderive3>=0.0.7
Requires-Dist: pystructs3>=0.0.8
Requires-Dist: pyserve3>=0.0.7
Requires-Dist: typing-extensions>=4.7.1

pydhcp
-------

[![PyPI version](https://img.shields.io/pypi/v/pydhcp3?style=for-the-badge)](https://pypi.org/project/pydhcp3/)
[![Python versions](https://img.shields.io/pypi/pyversions/pydhcp3?style=for-the-badge)](https://pypi.org/project/pydhcp3/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=for-the-badge)](https://github.com/imgurbot12/pydhcp/blob/master/LICENSE)
[![Made with Love](https://img.shields.io/badge/built%20with-%E2%99%A5-orange?style=for-the-badge)](https://github.com/imgurbot12/pydhcp)

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

### Installation

```
pip install pydhcp3
```

### DHCPv4 Examples

Packet Parsing

```python
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

```python
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

```python
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
)
```
