Skip to content

Log into UniFi controller and retrieve list of all known clients. Use this information to populate the /etc/hosts file with a mapping of IP/Username.

Notifications You must be signed in to change notification settings

ax42/unifi-to-hosts-mapping

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 

Repository files navigation

unifi-to-hosts-mapping

Within the UniFi controller you can create an alias for devices as they appear on the network. This script takes the alias entries and their corresponding IP address to maintain a list of hosts on the PiHole server. This host entry resides in /etc/hosts which the PiHole can be configured to use. The end result is the dashboard showing your configured hostname for Top Clients and not just an IP Address.

Basic workflow is as follows;

Image of PiHole/UniFi Workflow

Place script on PiHole server, in my case this is in /home/pi. You will also need to ensure you have the relevant python libraries installed.

sudo pip install python_hosts
sudo pip install unifi
sudo pip install netaddr

The script requires the controller IP (or hostname), controller username and password to function correctly. You can specify each of these via a command line parameter (-c, -u and -p), an environment variable (UNIFI_CONTROLLER, UNIFI_USER and UNIFI_PASSWORD), or interactively (in that order of precedence).

Create a suitable crontab entry for the root user, it will need to be for the root user as you are modifying the /etc/hosts file.

sudo 
crontab -e 

Add the following lines to the cron file and save/exit

0,15,30,45 * * * * /home/pi/build-static-dhcp.py

Finally, ensure you have selected "Reverse DNS lookup" for "Top Clients" within Settings on the PiHole Server

About

Log into UniFi controller and retrieve list of all known clients. Use this information to populate the /etc/hosts file with a mapping of IP/Username.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%