从Dnsmasq的日志里提取域名,并转换为conf文件

不啰嗦,看代码

import re
  
input_file_path = "/var/log/dnsmasq/dnsmasq.log"
output_file_path = "/home/xxx/cndomain.conf"
dns_server = "119.6.6.6"

with open(input_file_path, "r") as file:
    text = file.read()

pattern = r"[a-zA-Z]+\.(\w+\.\w+) "
matches = re.findall(pattern, text)

unique_domains = set(matches)

with open(output_file_path, "w") as file:
    for domain in unique_domains:
        file.write(f"server=/*.{domain}/{dns_server}\n")

发布者

湘笃秀

曲水流觞,维湘笃秀