Categories
Linux Networking Systems Administration

A script to scan a network range and create Kea DHCP reservations for devices it finds

This script is very simple. It will scan a network range attached to the device it is run from, and will turn what it finds into a list of reservations for the Kea dhcp server – https://kea.readthedocs.io/

You run it something like this, giving it a network range to scan. Then network should be a direct-attached link, or the output of the ARP command won’t make any sense:

~/g/netscan> python3 netscan.py 10.1.0.0/23

Output will be something like this. You can copy directly from the terminal or pipe to a file.

{
  # 2020-05-14 - jtuckey scan - mac: 2c:f4:32:d3:b6:16 - reversedns: arlec-pb-tv.lan
  "hw-address": "2c:f4:32:d3:b6:16",
  "hostname": "arlec-pb-tv.lan",
  "ip-address": "10.1.0.10",
},
{
  # 2020-05-14 - jtuckey scan - mac: 30:fd:38:c9:a2:29 - reversedns: livingroom-chromecast.lan
  "hw-address": "30:fd:38:c9:a2:29",
  "hostname": "livingroom-chromecast.lan",
  "ip-address": "10.1.0.12",
},
{
  # 2020-05-14 - jtuckey scan - mac: 78:0f:77:00:5a:67 - reversedns: livingroom-rmmini.lan
  "hw-address": "78:0f:77:00:5a:67",
  "hostname": "livingroom-rmmini.lan",
  "ip-address": "10.1.0.13",
},
{
  # 2020-05-14 - jtuckey scan - mac: a0:20:a6:01:6f:f9 - reversedns: dhtboy1.lan
  "hw-address": "a0:20:a6:01:6f:f9",
  "hostname": "dhtboy1.lan",
  "ip-address": "10.1.0.14",
},

The script should be easy to adapt for other uses also. Important link – https://gitlab.com/jaytuck/netscan – this is where the script itself is, as well as some hints on how to use it. Enjoy!

Leave a Reply

Your email address will not be published. Required fields are marked *