Small python module for reading /var/lib/dhcp/dhcpd.leases from isc-dhcp-server. This module works in Python 2.7 and 3.x
This module also supports reading lease files from the isc dhcp daemon running in IPv6 mode (Since version 0.4.0).
Installation
Through pypi
$ sudo pip install dhcp-leases
Through git
$ git clone git@github.com:acikogun/python-dhcp-leases.git
$ cd python-dhcp-leases
$ python setup.py build
$ sudo python setup.py install
Usage
from dhcp_leases import DhcpLeases
leases = DhcpLeases('/path/to/dhcpd.leases')
leases.get() # Returns the leases as a list of Lease objects
leases.get_current() # Returns only the currently valid dhcp leases as dict
# The key of the dict is the device mac address and the
# Value is a Lease object
Or read a gzip’ed file:
from dhcp_leases import DhcpLeases
# DhcpLeases(filename, gzip=False)
leases = DhcpLeases('/path/to/dhcpd.leases', True) # True param starts the gzip reader
leases.get() # Returns the leases as a list of Lease objects
leases.get_current() # Returns only the currently valid dhcp leases as dict
# The key of the dict is the device mac address and the
# Value is a Lease object
The Lease object has the following fields (only for IPv4 leases):
lease instanceof Lease
lease.ip # The ip address assigned by this lease as string
lease.ethernet # The mac address of the lease
lease.hardware # The OSI physical layer used to request the lease (usually ethernet)
lease.start # The start time of this lease as DateTime object
lease.end # The time this lease expires as DateTime object or None if this is an infinite lease
lease.hostname # The hostname for this lease if given by the client
lease.binding_state # The binding state as string ('active', 'free', 'abandoned', 'backup')
lease.data # Dict of all the info in the dhcpd.leases file for this lease
lease.valid # True if the lease hasn't expired and is not in the future
lease.active # True if the binding state is active
lease.options # List of extra options in the lease file
lease.sets # List of the 'set' items in the lease file
The Lease6 object has the following fields (only for IPv6):
lease instanceof Lease6
lease.ip # The ip address assigned by this lease as string
lease.type # If this is a temporary or permanent address. I's one of the following:
# Lease6.TEMPORARY: Temporary lease
# Lease6.NON_TEMPORARY: Non-temporary lease
# Lease6.PREFIX_DELEGATION: Delegated prefix lease
lease.host_identifier # The unique host identifier (replaces mac addresses in IPv6) as bytes
lease.host_identifier_string # The host_identifier property formatted as an hexadecimal string
lease.duid # The DHCP Unique Identifier (DUID) of the host as bytes
lease.iaid # The Interface Association Identifier (IAID) of the host
lease.last_communication # The last communication time with the host
lease.end # The time this lease expires as DateTime object or None if this is an infinite lease
lease.binding_state # The binding state as string ('active', 'free', 'abandoned', 'backup')
lease.preferred_life # The preferred lifetime in seconds
lease.max_life # The valid lifetime for this address in seconds
lease.options # List of extra options in the lease file
lease.sets # List of the 'set' items in the lease file
lease.data # Dict of all the info in the dhcpd6.leases file for this lease
Unit tests
The unit tests can be run with setup.py:
$ python3 setup.py test
# With coverage report:
$ coverage run setup.py test
Metadata
Release files for dhcp-leases 0.1.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| dhcp-leases-0.1.6.tar.gz | 11.0 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| dhcp_leases-0.1.6-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 22.7 kB
Release files / dhcp-leases-0.1.6.tar.gz
| Download URL | dhcp-leases-0.1.6.tar.gz |
|---|---|
| Size | 11.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
980d5151e09de1fb3ada9ac8aaaa33837b39988ad8d6d0cc5a3d14f358f8f9cf
|
|
BLAKE2b-256 checksum How to use checksums |
6f289db8682b541abc576a88e3acd7815207271bb5a6798d5c19880eae96ecf7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2
|
Release files / dhcp_leases-0.1.6-py3-none-any.whl
| Download URL | dhcp_leases-0.1.6-py3-none-any.whl |
|---|---|
| Size | 11.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f099e6170313ce26ba0eb58203637c6c87ec7eea8a869eff93bffe58010ffa4d
|
|
BLAKE2b-256 checksum How to use checksums |
bfd53f1c6f28925df7e91a58d8d9be6bbfc2d61cdc6e6d827f89443a7232266c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2
|
Security for dhcp-leases 0.1.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.