Skip to content

Instantly share code, notes, and snippets.

@toxicantidote
Last active April 27, 2025 16:27
Show Gist options
  • Save toxicantidote/568373a781f7074814965bb8654a128f to your computer and use it in GitHub Desktop.
Save toxicantidote/568373a781f7074814965bb8654a128f to your computer and use it in GitHub Desktop.
Uses LANcache DNS lists to create a DNSmasq compatible config file to redirect DNS queries to an existing LANcache server
## LANcache server IP
cache_ip = '192.168.0.1'
## DNSmasq output file (don't overwrite main config)
## Add "conf-file=/etc/dnsmasq.lancache" to the bottom of /etc/dnsmasq.conf to activate
output_file = '/etc/dnsmasq.lancache'
###
import requests
import os
import datetime
script_path = os.path.abspath(__file__)
with open(output_file, 'w') as out:
out.write('## This file is automatically generated by ' + script_path + '\n')
out.write('## Last updated ' + str(datetime.datetime.now()) + '\n')
out.write('address=/cache/' + cache_ip + '\n')
repo_info = requests.get('https://raw.githubusercontent.com/uklans/cache-domains/refs/heads/master/cache_domains.json')
repo_info_json = repo_info.json()
for domain in repo_info_json['cache_domains']:
name = str(domain['name'])
description = str(domain['description'])
file_list = domain['domain_files']
dns_list = []
for fname in file_list:
if fname == '': continue
dns_info = requests.get('https://raw.githubusercontent.com/uklans/cache-domains/refs/heads/master/' + fname)
for line in dns_info.text.split('\n'):
if line == '': continue
if line[:1] == '#': continue
dns_list.append(line)
print('Repository: ' + name)
print('Description: ' + description)
print('DNS entries: ' + str(dns_list))
out.write('\n## ' + name + ' - ' + description + '\n')
for name in dns_list:
if name[:1] == '*':
out.write('cname=' + name + ',cache\n')
else:
out.write('address=/' + name + '/' + cache_ip + '\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment