Code Monkey home page Code Monkey logo

dhcp-pihole-sync's Introduction

DHCP-PiHole-Sync

TL;DR: I needed a way to block YouTube from kids on the home network entirely, regardless of the device they were using, whilst still allowing adults to watch YouTube when required.

By syncing with DHCP static leases, I don't have to worry about updating multiple systems to identify clients.

My Pi-hole has two groups:

  • the default group (ID 0) that has YouTube-blocking regexes applied
    • All new clients are added to this group and are unable to access YouTube.
    • This includes synced DHCP clients, and other clients Pi-hole has seen - even if they have not been explicitly assigned a group.
    • Therefore, new devices on the network are automatically blocked.
  • the "Allow YouTube" group (ID 1) that does not have these regexes applied.

I make use of a Telegram bot to control YouTube access. I can send /getclients to receive an up-to-date list of all configured Pi-hole clients, and select a client to enable or disable YouTube access (by switching the groups).

When switching groups, any other groups (i.e. ad-blocking groups) are ignored and your own configuration is preserved.

This means that I can enable YouTube on a TV for example, for only the time that I am watching it - ensuring that kids still can't access it on another device or after I've finished watching and re-disabled it!

Note: This is only DNS-level blocking. You should use a firewall block all other outgoing traffic on port 53 to ensure devices cannot use their own DNS servers, circumventing this. Smart TVs and streaming devices are prone to this - Google/Android TV in particular likes to ignore DNS servers obtained over DHCP.

Usage

Change the appropriate parameters in the main.go file, build it, and run it as a system service.

For now I won't be providing more detailed instructions as I doubt many people will actually be running this.

It might break through Pi-hole updates as it replicates the web interface requests, rather than using the built-in API.

I wrote the code of an evening so it's not exceptionally well-written, but it seems to work...

dhcp-pihole-sync's People

Contributors

thisisnoahevans avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.