• Stars
    star
    121
  • Rank 293,924 (Top 6 %)
  • Language
    Python
  • License
    MIT License
  • Created over 10 years ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

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

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

# 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

$ 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

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:

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

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

More Repositories

1

gpsd-py3

Python 3 GPSD client
Python
104
star
2

pyElectronics

Python 3 library for working with electronics
Python
73
star
3

car-tracker

ESP8266 based gps car tracker
Arduino
25
star
4

setres

Set the resolution in xorg
Python
24
star
5

cardscan

Python command-line tool to parse scanned documents with cards to various data structures
Python
22
star
6

pyatem-win

Windows builds for https://git.sr.ht/~martijnbraam/pyatem
Python
12
star
7

pygments-theme-darcula

The darcula theme from Jetbrains IDEA for pygments
CSS
8
star
8

webcine

Webbrowser based mediacenter written in python
Python
7
star
9

odb2chrome

ODB2 interface in chrome and chromeOS using an ELM327 compatible adapter
CSS
6
star
10

OpenPedalFX

Open source digital guitar pedals
C
5
star
11

huawei-3g

Python module for controlling huawei 3g usb modems
Python
4
star
12

pvoutput

Python
4
star
13

globrun

Replacement for find|xargs
Python
4
star
14

Nebuchadnezzar

Linux native chat client (GTK2) for the matrix network
C#
3
star
15

pcb-re-toolkit

Reverse engineering tool for printed circuit boards
JavaScript
3
star
16

pmbootstrap-gtk

GTK3 based wizard for pmbootstrap
Python
3
star
17

aegir-bara

HTML5 theme for aegir
CSS
2
star
18

drush-queued

Python script o replace hosting-queued
Python
2
star
19

hosting_realtime_queue

Update the Aegir task queue in realtime with server sent events
JavaScript
2
star
20

blendqueue

Blender render queue using rabbitmq
Python
2
star
21

sse-proxy

Simple nodejs service that proxies server sent events from other applications
JavaScript
2
star
22

backupmanager

A wrapper to unify configuration/running backup tools
Python
1
star
23

codeclicker

Horrible weekend toy
1
star
24

wrsus

I will edit this description as soon as I remember what the acronym WRSUS meant
Python
1
star
25

wifite-ng

Rewrite of the wifite script
Python
1
star
26

imap-execute

Execute commands on new e-mail messages
Python
1
star
27

iso-manager

Python command line tool for downloading operating system cd images
Python
1
star
28

drupalorg-style-overrides

This generates a stylesheet with overrides for drupal.org. It contains some usability and style upgrades. Use some browser-specific module to inject the stylesheet.
CSS
1
star
29

distro

Python module to get linux distro information
Python
1
star
30

nitrogen-randomizer

Nitrogen wallpaper randomizer
Python
1
star