不啰嗦,看代码
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")