All Projects → MartijnBraam → Python Isc Dhcp Leases

MartijnBraam / Python Isc Dhcp Leases

Licence: mit
Small python module for reading /var/lib/dhcp/dhcpd.leases from isc-dhcp-server

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Python Isc Dhcp Leases

Boots
Lightweight bootstrap library for your Kotlin, Java and Android apps
Stars: ✭ 86 (-4.44%)
Mutual labels:  library
Neatinput
A .NET standard project which aims to make keyboard and mouse input monitoring easy on Windows and eventually Linux.
Stars: ✭ 89 (-1.11%)
Mutual labels:  library
Xdg
Go implementation of the XDG Base Directory Specification and XDG user directories
Stars: ✭ 88 (-2.22%)
Mutual labels:  library
Beet.js
Polyrhythmic Sequencer library for Web Audio API.
Stars: ✭ 87 (-3.33%)
Mutual labels:  library
Lsleases
list assigned ip from any device in your network
Stars: ✭ 88 (-2.22%)
Mutual labels:  dhcp
Zzdj dhcp
一个可以自动同步DHCP租用信息到数据库的微服务
Stars: ✭ 89 (-1.11%)
Mutual labels:  dhcp
Fann
Official github repository for Fast Artificial Neural Network Library (FANN)
Stars: ✭ 1,259 (+1298.89%)
Mutual labels:  library
Cog
A Persistent Embedded Graph Database for Python
Stars: ✭ 90 (+0%)
Mutual labels:  library
Discord.js Menu
💬 Easily create Discord.js v12 embed menus with reactions and unlimited customizable pages.
Stars: ✭ 89 (-1.11%)
Mutual labels:  library
Functionalplus
Functional Programming Library for C++. Write concise and readable C++ code.
Stars: ✭ 1,286 (+1328.89%)
Mutual labels:  library
Async Gamequery Lib
A high-performance java game query library designed for steam/source based games and others
Stars: ✭ 88 (-2.22%)
Mutual labels:  library
Libtelegram
Fast, efficient, header-only C++ Telegram bot API library using polling or FastCGI
Stars: ✭ 88 (-2.22%)
Mutual labels:  library
Ccxt.net
CCXT.NET – CryptoCurrency eXchange Trading Library for .NET
Stars: ✭ 89 (-1.11%)
Mutual labels:  library
Floatingtoast
Android library to create customizable floating animated toasts like in Clash Royale app
Stars: ✭ 86 (-4.44%)
Mutual labels:  library
Spider
A small dart library to generate Assets dart code from assets folder.
Stars: ✭ 90 (+0%)
Mutual labels:  library
Vlog
An in-display logging library for Android 📲
Stars: ✭ 86 (-4.44%)
Mutual labels:  library
Test Each
🤖 Repeat tests. Repeat tests. Repeat tests.
Stars: ✭ 89 (-1.11%)
Mutual labels:  library
Tor Android
Tor binary and library for Android
Stars: ✭ 90 (+0%)
Mutual labels:  library
Protobuf Nim
Protobuf implementation in pure Nim that leverages the power of the macro system to not depend on any external tools
Stars: ✭ 90 (+0%)
Mutual labels:  library
Nimpylib
Some python standard library functions ported to Nim
Stars: ✭ 88 (-2.22%)
Mutual labels:  library

python-isc-dhcp-leases

|Build Status| |PyPI version| |Coverage Status|

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


.. code:: bash

    $ sudo pip install isc_dhcp_leases

Through your distribution package manager

This python module is currently packaged in Debian unstable (release for Debian 9) and will be packaged in Ubuntu 17.04 (Zesty Zapus)

.. code:: bash

# For the python 2.7 interpreter
$ sudo apt install python-isc-dhcp-leases

# For the python 3 interpreter
$ sudo apt install python3-isc-dhcp-leases

Through git


.. code:: bash

    $ git clone [email protected]:MartijnBraam/python-isc-dhcp-leases.git
    $ cd python-isc-dhcp-leases
    $ python setup.py build
    $ sudo python setup.py install

Usage
-----

.. code:: python

    from isc_dhcp_leases import Lease, IscDhcpLeases

    leases = IscDhcpLeases('/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:

.. code:: python

    from isc_dhcp_leases import Lease, IscDhcpLeases
    # IscDhcpLeases(filename, gzip=False)
    leases = IscDhcpLeases('/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):

.. code:: python

    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):

.. code:: python

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

.. code:: bash

    $ python3 setup.py test
    # With coverage report:
    $ coverage run setup.py test

.. |Build Status| image:: https://travis-ci.org/MartijnBraam/python-isc-dhcp-leases.svg?branch=master
   :target: https://travis-ci.org/MartijnBraam/python-isc-dhcp-leases
.. |PyPI version| image:: https://badge.fury.io/py/isc_dhcp_leases.svg
   :target: http://badge.fury.io/py/isc_dhcp_leases
.. |Coverage Status| image:: https://coveralls.io/repos/MartijnBraam/python-isc-dhcp-leases/badge.svg
   :target: https://coveralls.io/r/MartijnBraam/python-isc-dhcp-leases
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].