Small python module for reading /var/lib/dhcp/dhcpd.leases from isc-dhcp-server
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
dhcp-leases-0.1.6.tar.gz
(11.0 kB
view details)
Built Distribution
File details
Details for the file dhcp-leases-0.1.6.tar.gz
.
File metadata
- Download URL: dhcp-leases-0.1.6.tar.gz
- Upload date:
- Size: 11.0 kB
- Tags: Source
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 980d5151e09de1fb3ada9ac8aaaa33837b39988ad8d6d0cc5a3d14f358f8f9cf |
|
MD5 | c4a806c3220a8fb9b14e51d3efb36739 |
|
BLAKE2b-256 | 6f289db8682b541abc576a88e3acd7815207271bb5a6798d5c19880eae96ecf7 |
File details
Details for the file dhcp_leases-0.1.6-py3-none-any.whl
.
File metadata
- Download URL: dhcp_leases-0.1.6-py3-none-any.whl
- Upload date:
- Size: 11.7 kB
- Tags: Python 3
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f099e6170313ce26ba0eb58203637c6c87ec7eea8a869eff93bffe58010ffa4d |
|
MD5 | 0954a1fa6afc1f9e0b9450de85ed1d9b |
|
BLAKE2b-256 | bfd53f1c6f28925df7e91a58d8d9be6bbfc2d61cdc6e6d827f89443a7232266c |