1

Script to keep track of profiles

I wanted to group my home network into different users and certain devices for finer grained parental controls and to be able to group certain devices (i.e. security cameras), so I used the `nextdns config set` command like so:

> sudo nextdns config set -profile AA-BB-CC-DD-EE-FF=12345 -profile BB-CC-DD-EE-FF-00=34567 98765

(Let's say those are two devices on two different profiles with a default of `98765`.)

Ok, now, I wanted to add a device with a new profile id. But, I also wanted to know what is currently there.

To solve this, I made a yaml config like this:

profiles:
- id: 12345 # Person A
  conditions:
  - AA-BB-CC-DD-EE-FF # Some Device
  - BB-CC-DD-EE-FF-00 # Another Device
- id: 34567 # Person B
  conditions:
  - AA-BB-CC-DD-EE-FF # Person B's Chromebook
- id: a5dbd2 # Default

And I made the following small script to get the command to update NextDNS:
 

import yaml
import argparse

parser = argparse.ArgumentParser(
    prog='Get NextDNS Setup CMD',
    description='Takes a nextdns-profiles.yaml file and outputs a command to setup NextDNS')

parser.add_argument('--filename', default='nextdns-profiles.yaml', required=False)

def main(args):
    with open(args.filename, 'r') as f:
        data = yaml.load(f, yaml.Loader)

    cmd_parts = ["nextdns config set"]

    for profile in data['profiles']:
        if "conditions" not in profile:
            cmd_parts.append(f"-profile {profile['id']}")
            continue

        for condition in profile["conditions"]:
            cmd_parts.append(f"-profile {condition}={profile['id']}")

    print(" ".join(cmd_parts))

if __name__ == '__main__':
    args = parser.parse_args()
    main(args)

 

I run that command with that YAML file and I can get the command to update NextDNS.

This solves being able to keep track of what is what. I now have a YAML file with comments that I can use if I ever need to update NextDNS's config. I also do not need to search my bash history or try to remember what the format of that command is.

I am posting this as something helpful for others to who are having this issue, but also wondering how others handle managing lists of device IDs and pairing them with profile IDs for their home networks.

1 reply

null
    • Failsafe
    • 10 mths ago
    • Reported - view

    Kudos! I'm a big fan of python, so I'm happy to see you share this for the community. 👍

Content aside

  • 1 Likes
  • 10 mths agoLast active
  • 1Replies
  • 70Views
  • 1 Following